Page life cycle Asp.net

Share the joy
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Trick to learn –> “SILVER”

Page Life Cycle Stages

I general, when a user request a page through his/her browser then page goes through several stage outlined in the following list. In addition to the page life-cycle stages, there are application stages that occur before and after a request but are not specific to a page. The stages are:-
  1. Page Request: – Page Request occurs before page life cycle begins. When user requested the page, ASP.Net determines that the page is needed to be parsed and compiled or whether a cached version of the page can be sent in response without running the page.
  2. Start: – In the start stage, page properties such as Request and Response is set. At this stage, page also determines that request is post back or a new request and sets the IsPostBack property.
  3. Page Initialization: – During page initialization, controls on the page are available and each control’s UniqueID property is set. A master page and themes are also applied to the page if applicable. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.
  4.  Load: – During Load, if the current request is postback, control properties are loaded with information recovered from view state.
  5. Validation: – During validation, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page.
  6. Postback Event Handling: – If the request is a postback, any event handlers are called. The event handling for server controls occurs during this stage.
  7. Rendering Unload: – Before rendering, view state is saved for the page and all controls. During the rendering stage, the page calls the Render method for each control, providing a text writer that writes its output to the OutPutStream object of the page’s Response property.

Trick to Learn Page life cycle stages  “SILVER”

SILVER

S –> START
I  –> INITIALIZATION
L –> LOAD
V –> VALIDATION
E –> EVENT HANDLER
R –> RENDERING

Page Life Cycle Events

Within each stage of page life cycle, page raises several events that we can handle to run our own code. Pages also support automatic event wire-up, meaning that ASP.NET looks for methods with particular names and automatically runs those methods when certain events are raised. These events are:-
  1. PreInit: – Raised after the start stage complete and before initialization stage begins.
  2. Init:- Raised after all controls have been initialized and any skin settings have been applied. The Init event of individual controls occurs before Init event of page.
  3. InitComplete: – Raised at the end of the initialization stage.
  4.  PreLoad: – Raised after the page loads view state of itself and all controls
  5. Load: – OnLoad event is occurred during the Load stage.
  6. Control Events: – Use these events to handle specific control events, such as Button’s Onclick event.
  7. LoadComplete: – Raised at the end of the event-handling stage.
  8. PreRender: – Raised after the Page object has created all controls that are required in order to render the page, including child controls of composite controls.
  9. PreenderComplete: – Raised after each data bound control whose DataSourceID property is set calls its DataBind method.
  10.  SaveStateComplete: – Raised after view state and control state have been saved for the page and for all controls.
  11.  Render: – This is not an event; instead, at this stage of processing, the Page object calls this method on each control. All ASP.NET Web server controls have a Render method that writes out the control’s markup to send to the browser.
  12.  Unload: – Raised for each control and then for the page.

Share the joy
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.