S
Stephen Miller
Hi,
I'm just looking at the web control life cycle and it appears that the
SaveViewState method SaveViewState is called twice.
To demonstrate, I overrode each method of the Web Control Life Cycle
with a 'Page.Trace' command (note that the string '-> SaveViewState'
appears only once):
// 2: Object Initialization
protected override void OnInit(EventArgs e) {
Page.Trace.Write (" -> OnInit");
base.OnInit(e);
if (Page != null){
Page.RegisterRequiresPostBack(this);
}
}
// 3: Begin Tracking View State
protected override void TrackViewState () {
Page.Trace.Write (" -> TrackViewState");
base.TrackViewState();
}
// 3a: Postback -> LoadViewState
protected override void LoadViewState(Object viewState) {
Page.Trace.Write (" -> LoadViewState");
if (viewState == null) {
base.LoadViewState(viewState);
}
}
// 4: Load
protected override void OnLoad (EventArgs e) {
Page.Trace.Write (" -> OnLoad");
base.OnLoad(e);
}
// 5: PreRender
protected override void OnPreRender (EventArgs e) {
Page.Trace.Write (" -> OnPreRender");
base.OnPreRender(e);
}
// 6: Save View State
protected override object SaveViewState () {
Page.Trace.Write (" -> SaveViewState");
return base.SaveViewState();
}
// 7: Render
protected override void RenderContents(HtmlTextWriter writer){
Page.Trace.Write (" -> RenderContents");
writer.Write ("my test control");
}
// 9: Dispose
public override void Dispose(){
Page.Trace.Write (" -> Dispose");
base.Dispose();
}
I then compiled my control and added to a new WebForm and enabled
tracing in the page directive ('<%@ Page Trace=true ...'). The Trace
Information for the page indicates that my overridden SaveViewState
method was called twice, immediately before and after the 'Begin
SaveViewState' section:
Begin Init
-> OnInit
-> TrackViewState
End Init
-> OnLoad
Begin PreRender
-> OnPreRender
End PreRender
-> SaveViewState
Begin SaveViewState
-> SaveViewState
End SaveViewState
Begin Render
-> RenderContents
End Render
Is this expected? If so what does it mean?
Thanks,
Stephen
I'm just looking at the web control life cycle and it appears that the
SaveViewState method SaveViewState is called twice.
To demonstrate, I overrode each method of the Web Control Life Cycle
with a 'Page.Trace' command (note that the string '-> SaveViewState'
appears only once):
// 2: Object Initialization
protected override void OnInit(EventArgs e) {
Page.Trace.Write (" -> OnInit");
base.OnInit(e);
if (Page != null){
Page.RegisterRequiresPostBack(this);
}
}
// 3: Begin Tracking View State
protected override void TrackViewState () {
Page.Trace.Write (" -> TrackViewState");
base.TrackViewState();
}
// 3a: Postback -> LoadViewState
protected override void LoadViewState(Object viewState) {
Page.Trace.Write (" -> LoadViewState");
if (viewState == null) {
base.LoadViewState(viewState);
}
}
// 4: Load
protected override void OnLoad (EventArgs e) {
Page.Trace.Write (" -> OnLoad");
base.OnLoad(e);
}
// 5: PreRender
protected override void OnPreRender (EventArgs e) {
Page.Trace.Write (" -> OnPreRender");
base.OnPreRender(e);
}
// 6: Save View State
protected override object SaveViewState () {
Page.Trace.Write (" -> SaveViewState");
return base.SaveViewState();
}
// 7: Render
protected override void RenderContents(HtmlTextWriter writer){
Page.Trace.Write (" -> RenderContents");
writer.Write ("my test control");
}
// 9: Dispose
public override void Dispose(){
Page.Trace.Write (" -> Dispose");
base.Dispose();
}
I then compiled my control and added to a new WebForm and enabled
tracing in the page directive ('<%@ Page Trace=true ...'). The Trace
Information for the page indicates that my overridden SaveViewState
method was called twice, immediately before and after the 'Begin
SaveViewState' section:
Begin Init
-> OnInit
-> TrackViewState
End Init
-> OnLoad
Begin PreRender
-> OnPreRender
End PreRender
-> SaveViewState
Begin SaveViewState
-> SaveViewState
End SaveViewState
Begin Render
-> RenderContents
End Render
Is this expected? If so what does it mean?
Thanks,
Stephen