Friday, December 9, 2011

Learn Tutorial of Page Life Cycle

Please visit my new Web Site

When a user send request to the Web server, the page passes a lot of events during initialization and disposal. Generally an aspx page contains a lot of server side controls as well as HTML controls & user controls. Most of the developer does not bother the life cycle events. But its not a good practice because to be a good & knowledgeable developer or programmer you have to learn the Life Cycle of an aspx page. Otherwise you will be failed to get advantage specially when developing user controls. It's also a common & crucial or vital question on interview viva or written exam.

For better understanding I have divide the Sequential loading of page cycle in two ways as follows:

1. First time request of a page
2. Postback of a page

See the initial level summary from below: interview question page life cycle

First time request of a page:
1. Object Initialization: Creates instance of the server control. The initialization event can be overridden using the OnInit method. The event associated with the cycle is Page_Init. In this phase the page knows the types of objects and how many to create.

2. Loading: The instance of the control is loaded onto the page object in which it is defined. In this phase you can catch the objects through Javascript like objects visibility, width, height and value. The Load event can be overridden by calling OnLoad method. The event associated with the cycle is Page_Load.

3. PreRendering: Associated value of the control is assigned. This is the last time changes of objects to save into the viewstate. After the execution of the method controls value is locked for the viewstate. The PreRender step can be overridden using OnPreRender method. The event associated with the cycle is Page_PreRender.

4. Saving: The state values of the control is saved to the viewstate.The value is attached in the HTML tag which we found in the browser view source action menu. It can be overridden by calling SaveViewState method.

5. Rendering: In this page corresponding HTML tag of the controls will be created. It can be overridden by calling OnPreRender method. The event associated with the cycle is Page_Render.

6. Disposing: At this stage the pages objects will be disposed. Basically this is the cleanup stage. Close all files, DB connections in this stage.

7. Unloading: This is the final event in the life cycle of the server control. In this phase all server control instances will be destroyed. The event associated with the cycle is Page_UnLoad.

Postback of a page:
1. Initializing: Same as before.
2. Loading View State: In this stage controls are populated with the appropriate viewstate data.
3. Loading: Same as before.
4. Loading the postback data: In this phase updates the control state with the correct postback data.
5. PreRendering: Same as before.
6. Saving State: The change of control between the current request and the previous request of the page is saved. For each change, the corresponding event is raised. For example, if the text of a textbox is changed, the new text is saved and a text_change event is raised.
7. Rendering: Same as before.
8. Disposing: Same as before.
9. Unloading: Same as before.

Hope it will help you alot for preparing interview viva.


Want to say something?

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash