Page Event
|
Controls Initialized
|
Is ViewState Enabled
|
When is this Event Raised
|
Logic
|
PreInit |
No | No | After the start stage is complete and before the initialization stage begins | This event can be used
for the following: 1) Check the IsPostBack property. The IsCallback and IsCrossPagePostBack properties are also set at this time. 2) Create or re-create dynamic controls. 3) Set a master page dynamically. 4) Set the Theme property dynamically. 5) Read or set profile property values.
Note: If the request is a postback,
the values of the controls have not yet been restored from view state.
|
Init |
Not guaranteed | No | After all controls have been initialized and any skin settings have been applied. The Init event of individual controls occurs before the Init event of the page. | This event can be used to read or initialize control properties. |
InitComplete |
Not guaranteed | Yes | At the end of the page’s initialization stage. | Only one operation takes place between the Init and InitComplete events: tracking of view state changes is turned on. View state tracking enables controls to persist any values that are programmatically added to the ViewState collection. This event can be used to make changes to view state that you want to make sure are persisted after the next postback. |
LoadViewState |
Not guaranteed | Yes | This event happens only at postbacks | The Viewstate which has been saved in the __VIEWSTATE during the previous
page visit (via the SaveViewState
event) is loaded and then populated into the control hierarchy.
|
LoadPostbackdata |
Not guaranteed | Yes | This event happens only at postbacks | During this event, the posted form data is loaded into the appropriate controls. |
PreLoad |
Yes | Yes | After the page loads view state for itself and all controls, and after it processes postback data that is included with the Request instance. | |
Load |
Yes | Yes | The Page object calls the OnLoad method on the Page object, and then recursively does the same for each child control until the page and all controls are loaded. The Load event of individual controls occurs after the Load event of the page. |
The OnLoad event can be used to set control properties and database connections. |
Control events |
Yes | Yes | Raised at the end of the event-handling stage. | These events can be used to handle specific control events, such as a Button control’s Click event or a TextBox control’s TextChanged event.
Note: In a postback request, if the page contains validator
controls, check the IsValid
property of the Page and of individual validation controls before performing
any processing.
|
LoadComplete |
Yes | Yes | Raised after the Page object has created all controls that are required in order to render the page, including child controls of composite controls. | This event can be used for tasks that require that all other controls on the page be loaded. |
PreRender |
Yes | Yes | The Page object raises the PreRender event on the Page object, and then recursively does the same for each child control. The PreRender event of individual controls occurs after the PreRender event of the page. |
The event can be used to make final changes to the contents of the page or its controls before the rendering stage begins. |
PreRenderComplete |
Yes | Yes | Raised after each data bound control whose DataSourceID property is set calls its DataBind method. |
|
SaveStateComplete |
Yes | Yes | Raised after view state and control state have been saved for the page and for all controls. |
Any changes to the page or controls at this point affect rendering, but the changes will not be retrieved on the next postback. |
Render |
Yes | Yes | 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. |
If you create a custom control, you typically override this method to output the control’s markup. However, if your custom control incorporates only standard ASP.NET Web server controls and no custom markup, you do not need to override the Render method. We do not need to explicitly render the control in code because a user control automatically incorporates rendering. |
Unload |
Yes | Yes | Raised for each control and then for the page. | This event can be used to do final cleanup for specific controls, such as closing control-specific database connections.
Note: During the
unload stage, the page and its controls have been rendered, so you cannot
make further changes to the response stream. If you attempt to call a method
such as the Response.Write method, the page will throw an
exception.
|
List ASP.NET Page Life Cycle events
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment