Wednesday, September 01, 2004

ASP.NET Page Execution

Here I want to explain the basics on what order events and methods get executed during the lifecycle of a request. Its essential to understand this order when debugging what can be complex bugs in Page and WebControl code.

Here's a short exercise that will help you internalize what is happening during the creation and execution of a page. Do this without looking up the answer, and it will really make you think through what is happening. Put the following events in order, assuming the request is a PostBack resulting from a Button click:

Unload
Pre-Render
Handle Postback Events
Dispose
Save State
Load View State
Load
Button Click Handler
Process Postback Data
Initialize
Send Postback Change Notifications
Render

You can lookup the answer in MSDN http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcontrolexecutionlifecycle.asp, but realize that at least one of the events is out of order in the documentation.

Consider the events in your Global.asax class on the first request received by an application not yet started:

Authorize Request
Application Start
Authenticate Request
End Request
Page Execution
Begin Request
Session Start

The next time you try to access ViewState during the Init event, you'll know why it doesn't work correctly.

With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

1 comment:

Mitesh V. Mehta said...

You can lookup the answer in MSDN http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcontrolexecutionlifecycle.asp, but realize that at least one of the events is out of order in the documentation.

Consider the events in your Global.asax class on the first request received by an application not yet started:

Authorize Request
Application Start
Authenticate Request
End Request
Page Execution
Begin Request
Session Start

The next time you try to access ViewState during the Init event, you'll know why it doesn't work correctly.

With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/