ASP.NET LIFE CYCLE
When an ASP.NET page runs, the page goes through a life cycle in which it performs a series of processing steps. It is important for us to understand the page life cycle. The Life cycle events are:
1. Page request
6. Control Events
1) PAGE REQUEST
The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.
In the start stage, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a post-back or a new request and sets the IsPostBack property.
• This is the first event which raised in asp.net page lifecycle
• Check for Request is for Post Back or not.
• All dynamic control need to be created
• Theme Change, Master Page Set at runtime
• Raised after all controls have been initialized
• Build up a tree of controls from the ASPX file.
• Turn on view state monitoring – any changes in control will be tracked by View State for future.
• Load view state data for page and controls.
• Load Postback data if needed.
• We can process any kind operation that need to perform before page load.
• OnLoad methods control called for each and every control.
• We can create the connection initialization for any kind of external source like database connection.
• We can also set the control properties.
7) EVENT CONTROL
• If this is an postback request , Corresponding events will triggered. Like, if the post back is happing for button click, then Button_Click Event will fired.
• Each control of the page has a PreRender event which is being invoked.
• EnsureChildControls is also being called during this events.
• DataBind method for all control has also been called.
• If we want to change any thing to any control this is the last event where we can do because after the pageRender starts
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.
• Pages calls the Render method for each and every control.
• Text writer that writes the output to the as output stream.
• Output steam set to the page's Response property.
• The Unload event is raised after the page has been fully rendered, sent to the client, and is ready to be discarded.
• At this point, page properties such as Response and Request are unloaded and cleanup is performed.