ASP.NET Page Life Cycle

When a visitor first requests a .aspx page on your server, the server sends it to the HTTP Pipeline. The HTTP Pipeline handles the conversion of application code into HTML. The first class initiated is called HttpRuntime. This class finds a free HttpApplication object to start processing the request. The HttpApplication object then runs the appropriate handler assigned in the web.config and machine.config files for the requested extension. The .aspx extension handled by the HandlerClass or HandlerFactory class. The HttpApplication object starts the IHttpHandler interface which begins processing the application code by calling the processRequest() method. The processRequest() method then calls the FrameworkInitialize() method which begins building the control trees for the requested page. Now the processRequest() method cycles through the page\’s life cycle in the order listed below.

Page_InitPage Initialisation
LoadViewStateView State Loading
LoadPostDataPostback Data Processing
Page_LoadPage Loading
RaisePostDataChangedEventPostback Change Notification
RaisePostBackEventPostback Event Handling
Page_PreRenderPage Pre Rendering Phase
SaveViewStateView State Saving
Page_RenderPage Rendering
Page_UnloadPage Unloading

The first processing method is Page_Init(). Once the control tree has been created, controls declared in the .aspx page are initialized. Settings of controls will modify in this method to be used later in the page life cycle. The next processed method is LoadViewState(). The ViewState contains stored information that is set by the page and controls. The next processed method is LoadPostData(). These are values associated with the HTML form elements the visitor has typed, changed or selected in the page. The next processed method is Page_Load(). This method is very familiar and common used method in ASP.NET server-side application. All the code in this method executed once at the beginning of the page. The next processed method is RaisePostDataChnagedEvent(). Whenever a visitor completed the submit button, an event will be triggered. This change in state signals the page to do something. The next processed method is RaisePostBackEvent(). This method allows the page to know what event has been triggered and which method to call. The next processed method is Page_PreRender(). This method is the last chance for the ViewState to be changed based on the PostBackEvent before the page is rendered. The next processed method is SaveViewState(). This method saves the updated ViewState to be processed on the next page. The final ViewState is encoded the ViewState hidden field on the page during the page render. The next processed method is Page_Render(). This method renders all of the application code to be outputted on the page. This action will happen with HtmlWriter object. The last processed method is Page_Unload(). During this method data can be released to free up the resources on the server for the processes. Once this method completed, HTML will be sent to the browser for client-side processing. This is it ??? The life cycle of an ASP.NET Page.


Leave a Reply

Scroll to Top
%d bloggers like this: