ASP.NET --Page Life Cycle
ASP.NET pages goes through various life cycle.In which page performs a set of processing steps.
Steps: Iinitialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering. If we understand the page life cycle we can write the appropriate code. Suppose we are developing custom controls, in that case page life cycle is very important.
General Page Life-cycle Stages
There are various stages in page.
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 or whether a cached version of the page can be sent in response without running the page.
Start-In this stage, page properties (Request and Response) are Set and also determines whether the request is a postback or a new request and sets the IsPostBack property. Additionally, during the start step, the page's UICulture property is set.
Page initialization- when page initialized, controls on the page are available and each control's UniqueID property is set. 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. Any themes are also applied to the page.
Load- In this stage, if the current request is a postback, control properties are loaded with information recovered from view state and control state.
Validation- Here, 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.
Rendering- Before this stage, view state is saved for the page and all controls.
During the rendering phase, the page calls the Render method for each control,
providing a text writer that writes its output to the OutputStream of the page's
Response property.
Unload- After the page has been fully rendered, unload is called. Then this is sent to the client, and is ready to be discarded. In this point, page properties such as Response and Request are unloaded and any cleanup is performed.
Life-cycle Events
PreInit- Use this event for the following situation
To Check the IsPostBack property, to determine whether this is the first time the page is being
To Create or re-create dynamic controls To Set a master page dynamically. To Set the Theme property dynamically To Read or set profile property values.
Init- Raised after all controls have been initialized.
InitComplete- Raised by the Page object. This event used for processing tasks that require all initialization be complete.
PreLoad- Use this event when you perform processing on your page or control before
the Load event. .
Load- OnLoad event method is used to set properties in controls and establish database connections.
Control events- this handles specific control events, such as a Button
control's Click event or a TextBox control's TextChanged event.
LoadComplete- all other controls on the page be loaded.
PreRender -Before this:
The Page object calls EnsureChildControls for each control and for the page. Each data bound control whose DataSourceID property is set calls its DataBind method.
The PreRender event occurs for each control on the page. Use the event to make final changes to the contents of the page or its controls
SaveStateComplete- Before this occurs, ViewState has been saved for the page and for all controls.
Any changes to the page or controls at this point will not be reflect.
Render - This is not an event. ASP.NET Web server controls have a Render method that writes out the control's markup that is sent to the browser.
Unload- This event occurs for each control and then for the page.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|