Page Life Cycle in ASP.NET

Life cycle when the page processed during a postback


The events associated with the relevant page cycle phases are:
  • Page Initialization: Page_Init
  • View State Loading:LoadViewState
  • Postback data processing: LoadPostData
  • Page Loading: Page_Load
  • PostBack Change Notification: RaisePostDataChangedEvent
  • PostBack Event Handling: RaisePostBackEvent
  • Page Pre Rendering Phase: Page_PreRender
  • View State Saving: SaveViewState
  • Page Rendering: Page_Render
  • Page Unloading: Page_UnLoad

The processing sequence in which a page is processed during a postback event is:
Initializing: During this phase, the server creates an instance of the server control
Loading view state: During this phase, the view state of the control posted by the client is reloaded into the new instance of the control.
Loading: During this phase, the instance of the control is loaded onto the page object in which it is defined.
Loading the postback data: During this phase, the server searches any data corresponding to the control that is loaded in the data posted by the client.
PreRendering: During this phase, the control is updated with the changes made to it. This prepares the control for rendering.
Saving state: During this phase, the change in the state 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.
Rendering: During this phase, the server creates the corresponding HTML tag for the control.
Disposing: During this phase, all cleanup tasks, such as closing files and database connections opened by the control are performed.
Unloading: During this phase, all cleanup tasks, such as destroying the instances of server control are performed. This is the final event in the life cycle of a server control
The following figure illustrates how the server controls on an ASP.NET page is processed by the server:



Page Life Cycle without Master Page or User Controls
  1. Page_PreInit
  2. Page_Init
  3. Page_InitComplete
  4. Page_PreLoad
  5. Page_Load
  6. Page_LoadComplete
  7. Page_PreRender 
  8. Page_UnLoad
Page Life Cycle With Master Page
  1. Page_PreInit
  2. MasterPage_Init
  3. Page_Init
  4. Page_InitComplete
  5. Page_PreLoad
  6. Page_Load
  7. MasterPage_Load
  8. Page_LoadComplete
  9. Page_PreRender
  10. MasterPage_PreRender
  11. MasterPage_UnLoad
  12. Page_UnLoad 
    Note: For MasterPage, PreInit, InitComplete, PreLoad, LoadComplete will not be fired.

 Page Life Cycle with Master Page or User Controls

  1. Page_PreInit
  2. UserControl_Init
  3. MasterPage_Init
  4. Page_Init
  5. Page_InitComplete
  6. Page_PreLoad
  7. Page_Load
  8. MasterPage_Load
  9. UserControl_Load
  10. Page_LoadComplete
  11. Page_PreRender
  12. MasterPage_PreRender
  13. UserControl_PreRender
  14. UserControl_UnLoad
  15. MasterPage_UnLoad
  16. Page_UnLoad
    Note: For MasterPage and UserControl, PreInit, InitComplete, PreLoad, LoadComplete will not be fired.

Comments

Popular posts from this blog

MVC Request Execution Stages - Life Cycle

Overview of MVC

ASP.NET MVC: Benefits

Introduction to ASP.Net MVC

Paged Data Source - Custom Paging

SOLID Principles with C#

Auto Sequence Number in Grid Control with Paging

ASP.NET MVC Version History

Managed Code and UnManaged Code