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:-
- 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.
- 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.
- 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.
- Load: – During Load, if the current request is postback, control properties are loaded with information recovered from view state.
- 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.
- Postback Event Handling: – If the request is a postback, any event handlers are called. The event handling for server controls occurs during this stage.
- 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”
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:-
- PreInit: – Raised after the start stage complete and before initialization stage begins.
- 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.
- InitComplete: – Raised at the end of the initialization stage.
- PreLoad: – Raised after the page loads view state of itself and all controls
- Load: – OnLoad event is occurred during the Load stage.
- Control Events: – Use these events to handle specific control events, such as Button’s Onclick event.
- LoadComplete: – Raised at the end of the event-handling stage.
- 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.
- PreenderComplete: – Raised after each data bound control whose DataSourceID property is set calls its DataBind method.
- SaveStateComplete: – Raised after view state and control state have been saved for the page and for all controls.
- 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.
- Unload: – Raised for each control and then for the page.
Share the joy