At every stage of its lifecycle, the page raises following events:
Stage PageInitialization - Events raised PreInit,Init,InitComplete
- PreInit - handles following tasks:
- The IsPostBack property is checked to determine if the page is being processed for the first time .
- Dynamic controls are created
- A master page is dynamically.
- Theme property is set dynamically.
- Profile property values are read or set.
Note : The values of the controls are not restored from viewstate yet if it's a postback. so if any control property is set during this event, its value might be overwritted in the next event.
- Init -
- Control properties are read or initialized.
- It's triggered after the controls are initialized and skin settings are applied.
- Initcomplete -
Stage LOAD - Events raised Preload, Load
- PreLoad -
- Once this event is triggered by Page, the view state of the page and all controls are loaded and any postback data included in the Request instance is processed.
- Load -
- Properties of the controls are set using OnLoad event.
- Database connections are established.
- The OnLoad event method of the page and its child control are called recursively until they all are loaded.
- Control events -
- Control specific events are handled at this stage. e.g. TextChanged event’s for a textbox.
- In a postback request, if the page contains validator controls, you should check the IsValid property of the page and of the individual validation controls before performing any processing.
- LoadComplete -
- For accessing controls that have been properly loaded.
- PreRender
- To make any final changes to the controls before they are rendered.
- Before this event , 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.
- SaveStateComplete-
- Used for tasksthat require view state to be saved, yet not making any changes to the controls themselves.
- ViewState for the page and its controls are saved before this event occurs and thus any chhanges to the page or controls at this point will be ignored.
- Render
- The page object calls this method on all of the controls, so all the controls are written and sent to the browser.
Note: If a custom control incorporates only standard NET Web server controls and no custom markup, you do not need to override the Render method which you do normally for any custom control.
- Unload -
- A final cleanup for specific controls such as closing the control-specific database connections and open files, finishing up logging is performed here.
- The Unload event occurs for each control, and then for the page.
Note : No further changes to the response stream can be made now. All the controls UnLoad method are fired, followed by the pages UnLoad event (bottom-up). This stage is used for closing database connections, closing open files, etc.
- The Init, Unload event for each child control occur before its parent container corresponding event are raised. However the Load event for a container occurs before the Load events for its child controls (top-down).
Source of Reference: MSDN
No comments:
Post a Comment