ASP.NET Page Life Cycle

Whenever a page is requested after that it is loaded into the server memory, processed and sent to the browser. Then it is unloaded from the memory. You can also write your own code to override the default code.


The Page class creates a hierarchical tree of all the controls on the page. All the components on the page, except the directives are the part of this control tree. You can also see the control tree by adding trace= "true" to the Page directive.



The page life cycle phases:
Initialization
• Instantiation of the controls on the page
 • Restoration and maintenance of the state
 • Execution of the event handler codes
• Page rendering
The page life cycle of ASP.NET helps in writing custom controls and initializing them at right time, populate their properties with view-state data and run control behavior code.

Following are the different stages of an ASP.NET page:
Page request: At this phase, the ASP.NET gets a page request and then it decides whether to resolve and compile the page, accordingly the response is sent.
Starting of page life cycle: At this phase, the Request and Response objects are set. If the request is an old request or post back then the IsPostBack property of the page is set to true.

Page initialization: At this stage, the controls on the page are assigned unique ID by setting the UniqueID property and the themes are applied. For a new request, postback data is loaded and the control properties are restored to the view-state values.
Page load: At this phase, the user set the control properties using the view state and control state values.
Validation: Validate method of the validation control is called and on its successful execution, the IsValid property of the page is set to true.
Postback event handling: At this phase,The event handler is called if the request is a postback(old request).
Page rendering: At this phase, the view state for the page and all controls are saved. The page calls the Render method for each control and the output of rendering is written to the OutputStream class of the Page's Response property.

Unload: The rendered page is sent to the client and page properties, such as Response and Request, are unloaded and all cleanup done.
ASP.NET Page Life Cycle ASP.NET Page Life Cycle Reviewed by NEERAJ SRIVASTAVA on 12:44:00 PM Rating: 5

No comments:

Powered by Blogger.