Life-Cycle Events
Within each stage of the life cycle of a page, the page raises events that you can handle to run your own code.
Page Event
|
Typical Use
|
PreInit
|
Rose after the start stage is complete and before
the initialization stage begins.
Use this event for the following:
Note
|
Init
|
Rose after all controls has been
initialized and any skin settings have been applied.
Use this event to read or
initialize control properties.
|
InitComplete
|
Raised at the end of the page's
initialization stage.
|
PreLoad
|
Raised 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
|
The Page object
calls the OnLoad method
on the Page object,
occurs after the Load event
of the page.
Use the OnLoad event
method to set properties in controls and to establish database connections.
|
Control
events
|
Use these events to handle
specific control events, such as a Button control's Click event,a TextBox control's TextChangedevent.
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
|
Raised at the end of the
event-handling stage.
Use this event for tasks that
require that all other controls on the page be loaded.
|
PreRender
|
Raised after the Page object
has created all controls that are required in order to render the page,
The Page object
raises the PreRender event
on the Page object, ThePreRender event
of individual controls occurs after the PreRender event
of the page.
Use the event to make final
changes to the contents of the page or its controls before the rendering
stage begins.
|
PreRenderComplete
|
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.
If you create a custom control,
you typically override this method to output the control's markup.
A user control (an .ascx file)
automatically incorporates rendering, so you do not need to explicitly render
the control in code.
|
Unload
|
Raised for each control and then
for the page.
In controls, use this event to do
final cleanup for specific controls, such as closing control-specific
database connections.
For the page itself, use this
event to do final cleanup work, such as closing open files and database
connections, or finishing up logging or other request-specific tasks.
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.
|
No comments:
Post a Comment