Web Form Life Cycle

Introduction


Every request for a page made from a web server causes a chain of events at the server. These events, from beginning to end, constitute the life cycle of the page and all its components. The life cycle begins with a request for the page, which causes the server to load it. When the request is complete, the page is unloaded. From one end of the life cycle to the other, the goal is to render
appropriate HTML output back to the requesting browser. The life cycle of a page is marked by the following events, each of which you can handle yourself or leave to default handling by the ASP.NET server:
Initialize:
Initialize is the first phase in the life cycle for any page or control. It is here that you initialize any settings needed for the duration of the incoming request.
Load View State:
The ViewState property of the control is populated. The ViewState information comes from a hidden variable on the control, used to persist the state across round trips to the server. The input string from this hidden variable is parsed by the page framework, and the ViewState property is set. This can be modified via the LoadViewState( ) method. This allows ASP.NET to manage the state of your control across page loads so that each control is not reset to its default state each time the page is posted.
Process Postback Data:
During this phase, the data sent to the server in the posting is processed. If any of this data results in a requirement to update the ViewState, that update is performed via the LoadPostData( ) method.
Load:
CreateChildControls( ) is called, if necessary, to create and initialize server controls in the control tree. State is restored, and the form controls show client-side data. You can modify the load phase by handling the Load event with the OnLoad method.
Send Postback Change Modifications:
If there are any state changes between the current state and the previous state, change events are raised via the RaisePostDataChangedEvent( ) method.
Handle Postback Events:
The client-side event that caused the postback is handled.
PreRender:
This is the phase just before the output is rendered to the browser. It is essentially your last chance to modify the output prior to rendering using the OnPreRender( ) method.
Save State:
Near the beginning of the life cycle, the persisted view state was loaded from the hidden variable. Now it is saved back to the hidden variable, persisting as a string object that will complete the round trip to the client. You can override this using the SaveViewState( ) method.
Render:
This is where the output to be sent back to the client browser is generated. You can override it using the Render method. CreateChildControls( ) is called, if necessary, to create and initialize server controls in the control tree.
Dispose:
This is the last phase of the life cycle. It gives you an opportunity to do any final cleanup and release references to any expensive resources, such as database connections. You canmodify it using the Dispose( ) method.


Comments

Author: Bindu Bujji09 Jun 2008 Member Level: Gold   Points : 0

Thanks for sharing this.

Author: Sebastian13 Jun 2008 Member Level: Gold   Points : 1

This is very informative. Thanks for sharing the details.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: