Page Life Cycle Events in ASP.NET architecture

The sequence of events that are executed in the life cycle of a page.

The following are these events, listed in the order in which they are executed:

1. Page_Init
2. LoadViewState
3. LoadPostData
4. Page_Load
5. RaisePostDataChangedEvent
6. RaisePostBackEvent
7. Page_PreRender
8. SaveViewState
9. Page_Render
10. Page_UnLoad

These events can be overridden—that is, you can override them to implement your custom handlers—and are associated with their respective event handlers. The ASP.NET page life cycle events are discussed in the following steps:
  • The page life cycle starts with the invocation of the Page_Init event. This event is responsible for initializing the controls that you use in your page to their default values. This event can also be used to create or even re-create the controls in your web page that need to be created dynamically.
  • The next event handler that gets executed is the LoadViewState method that restores the View State for the web page. This method is only executed if and when the web page has been posted back and restores any previously stored View State data associated with the web page.
  • The next method to be executed in this chain of events is the LoadPostBackData. This method is responsible for processing the data of the server controls, and these controls are populated with the previously posted data.
  • The Page_Load event is triggered. This method can be used to populate and bind data to your controls either from the database or any other sources, states, and so on.
  • The RaisePostBackData and RaisePostBack events are triggered if, and only if, there was a postback. The PreRender event is fired next, and you can use this event to make any changes to the data contained in your controls prior to their rendering.
  • The Render event is triggered, which creates the Response object for the web page. Now the page is eventually rendered through the Render event, which uses a text writer to write the response stream to the Response.
  • The page is unloaded from the memory, and the Response object is sent to the browser in the Page Unload event. You can override this method to perform your necessary cleanup activities. According to MSDN, “Unload is called after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and any cleanup is performed.”
Tags: , , , ,
Hot on Web:


About author