Friday, May 22, 2009

Application, Page and Control events in ASP.NET

Page Events in Asp.Net 1.0/1.1
AbortTransaction.
CommitTransaction
DataBinding
Dispose
Error
Init
Load
PreRender
Unload

Page Events in ASP.Net 2.0
PreInit
Init
InitComplete
PreLoad
Load
LoadComplete
PreRender
PreRenderComplete
Unload

ASP.Net page events when master page included

When using master pages, the normal page event lifecycle is a little different. Here is the actual order:

Page: OnPreInit
MasterPageControl: OnInit
Control: OnInit
MasterPage: OnInit
Page: OnInit
Page: OnInitComplete
Page: LoadPageStateFromPersistenceMedium
Page: LoadViewState
MasterPage: LoadViewState
Page: OnPreLoad
Page: OnLoad
MasterPage: OnLoad
MasterPageControl: OnLoad
Control: OnLoad
OnXXX
MasterPage: OnBubbleEvent
Page: OnBubbleEvent
Page: OnLoadComplete
Page: OnPreRender
MasterPage: OnPreRender
MasterPageControl: OnPreRender
Control: OnPreRender
Page: OnPreRenderComplete
MasterPageControl: SaveControlState
Control: SaveControlState
Page: SaveViewState
MasterPage: SaveViewState
Page: SavePageStateToPersistenceMedium
Page: OnSaveStateComplete
MasterPageControl: OnUnload
Control: OnUnload
MasterPage: OnUnload
Page: OnUnload



Complete Flow Of Application,Control and Page Events

It appeared to me that they added a few things here and there to the Application, Page and Control lifecycle in ASP.NET v2.0. Curious, I whipped up some derived classes to output to a text file every time one of these events fired in the grand scheme of a request. I wired in the basic events then did overrides for everything that appeared to fire at some point. I think it's mostly complete, but the data binding events don't appear to fire unless you've got some data binding to do...

Application: BeginRequest
Application: PreAuthenticateRequest
Application: AuthenticateRequest
Application: PostAuthenticateRequest
Application: PreAuthorizeRequest
Application: AuthorizeRequest
Application: PostAuthorizeRequest
Application: PreResolveRequestCache
Application: ResolveRequestCache
Application: PostResolveRequestCache
Application: PreMapRequestHandler
Page: Construct
Application: PostMapRequestHandler
Application: PreAcquireRequestState
Application: AcquireReq uestState
Application: PostAcquireRequestState
Application: PreRequestHandlerExecute
Page: AddParsedSubObject
Page: CreateControlCollection
Page: AddedControl
Page: AddParsedSubObject
Page: AddedControl
Page: ResolveAdapter
Page: DeterminePostBackMode
Page: PreInit
Control: ResolveAdapter
Control: Init
Control: TrackViewState
Page: Init
Page: TrackViewState
Page: InitComplete
Page: LoadPageStateFromPersistenceMedium
Control: LoadViewState
Page: EnsureChildControls
Page: CreateChildControls
Page: PreLoad
Page: Load
Control: DataBind
Control: Load
Page: EnsureChildControls
Page: LoadComplete
Page: EnsureChildControls
Page: PreRender
Control: EnsureChildControls
Control: PreRender
Page: PreRenderComplete
Page: SaveViewState
Control: SaveViewState
Page: SaveViewState
Control: SaveViewState
Page: SavePageStateToPersistenceMedium
Page: SaveStateComplete
Page: CreateHtmlTextWriter
Page: RenderControl
Page: Render
Page: RenderChildren
Control: RenderControl
Page: VerifyRenderingInServerForm
Page: CreateHtmlTextWriter
Control: Unload
Control: Dispose
Page: Unload
Page: Dispose
Application: PostRequestHandlerExecute
Application: PreReleaseRequestState
Application: ReleaseRequestState
Application: PostReleaseRequestState
Application: PreUpdateRequestCache
Application: UpdateRequestCache
Application: PostUpdateRequestCache
Application: EndRequest
Application: PreSendRequestHeaders
Application: PreSendRequestContent

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.