31 May 2005

ASP,Net 1.x Page Lifecycle

Found a good overview for the order of events when executing an asp.net page here:

Use the following key for the events below:
Black - every time page is processed
Red - only if the request is transacted
Green - only on postback
Blue - only if tracing is enabled

Begin Transaction (only when transactions are enabled for the page)

Begin Transaction ProcessRequestTransacted()

TransactedCallback() on
Process Request Main
(described below)
Transactions.InvokeTransacted -- parts of the request that need to be done under transacted context

Process Request Main (every page, this is the main execution path)

Init InitRecursive()
Raise OnInit (recursive)
Begin tracking viewstate

LoadViewState LoadPageViewState()

ProcessPostData1 ProcessPostData(_requestValueCollection, true /* BeforeLoad */);
Hand postback data to the controls that exist before Page_Load

Load LoadRecursive();
Fire OnLoad() (recursive)

ProcessPostData2 ProcessPostData(_leftoverPostData, false /* BeforeLoad */);
Hand postback data to controls added in Load (using LoadControl, for example)

Raise ChangedEvents RaiseChangedEvents()
RaisePostDataChangedEvent() on each control with postback data that is not an IPostBackEventHandler

Raise PostBackEvent RaisePostBackEvent(_requestValueCollection)
RaisePostBackEvent() on the control that caused the postback

PreRender PreRenderRecursive()
if Page.Visible
EnsureChildControls() -- creates controls if they haven't already been created by databinding
Fire OnPreRender (recursive)

Build Trace Tree BuildProfileTree("ROOT", EnableViewState)

SaveViewState SavePageViewState()
Save state recursively for the page and it's controls

Render RenderControl(CreateHtmlTextWriter(Response.Output))
if Page.Visible
Render() (recursive)

Finish Transaction (only when transactions are enabled for the page)

End Transaction Fire OnAbortTransaction() or OnCommitTransaction()

End Trace (only when Tracing is enabled)

Trace.EndRequest if PageOutput

Process Request Cleanup (every request)
* Set Request and Response to null

UnloadRecursive UnloadRecursive()
Fire OnUnload() (recursive)

No comments: