Whenever you request an ASP.NET page, a particular set of events is raised in a particular sequence. This sequence of events is called the page execution lifecycle.
For example, we have already used the Page Load event in previous code samples in this chapter. You normally use the Page Load event to initialize the properties of controls contained in a page. However, the Page Load event is only one event supported by the Page class.
Here is the sequence of events that are raised whenever you request a page:
-
PreInit
-
Init
-
InitComplete
-
PreLoad
-
Load
-
LoadComplete
-
PreRender
-
PreRenderComplete
-
SaveStateComplete
-
Unload
Why so many events? Different things happen and different information is available at different stages in the page execution lifecycle.
For example, View State is not loaded until after the InitComplete event. Data posted to the server from a form control, such as a TextBox control, is also not available until after this event.
Ninety-nine percent of the time, you won't handle any of these events except for the Load and the PreRender events. The difference between these two events is that the Load event happens before any control events and the PreRender event happens after any control events.
No comments:
Post a Comment