Академический Документы
Профессиональный Документы
Культура Документы
Table of Contents
Introduction General Page Life-cycle Stages Life-cycle Events Stage and Event Mapping Catch-Up Events for Added Controls Data Binding Events for Data-Bound Controls Login Control Events
www.synechron.com
Introduction
When an ASP.NET page runs, the page goes through a life cycle in which it performs a series of processing steps. These include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering. Important to understand the page life cycle so that you can write code at the appropriate life-cycle stage for the effect you want.
www.synechron.com
Start
Initialization
Load
Unload
www.synechron.com
Init
Raised after all controls have been initialized and skin settings have been applied Note: Init event of individual control occurs before the Init event of the page Used for read or initialize control properties Raised at the end of InitComplete Only one operation takes place in-between. i.e. Tracking of View State changes is turned on. What is view state? Used for making changes to ViewState. Raised after page load view state for itself and controls and after it processes postback data included with Request Instance.
InitComplete
PreLoad
www.synechron.com
Control Events
Specific control events like Click of a button Raised at the end of event handling stage Used when all the controls on the page are loaded. Raised after all controls are created in Page object Page Object calls PreRender on itself and recursively on all controls Used for making final changes in page. Raised after each data bound control whose DataSourceID property is set calls its DataBind method. Raised after view state and control state have been saved for the page and for all controls.
LoadComplete PreRender
PreRenderComplete
SaveStateComplete
www.synechron.com
Unload
www.synechron.com
www.synechron.com
Life Cycle Events Logical flow of request process(contd) Step 3 (P: ASP.NET page): Once the HttpHandler logic executes, the ASP.NET page object is created. While the ASP.NET page object is created, many events are fired which can help us to write our custom logic inside those page events. There are 6 important events which provides us placeholder to write logic inside ASP.NET pages Init, Load, validate, event, render and unload. Step4 (M: HttpModule): Once the page object is executed and unloaded from memory, HttpModule provides post page execution events which can be used to inject custom post-processing logic. There are 4 important post-processing events PostRequestHandlerExecute, ReleaserequestState, UpdateRequestCache and EndRequest.
www.synechron.com
Section HttpModule
Event BeginRequest
Description This event signals a new request; it is guaranteed to be raised on each request. This event signals that ASP.NET runtime is ready to authenticate the user. Any authentication code can be injected here. This event signals that ASP.NET runtime is ready to authorize the user. Any authorization code can be injected here.
HttpModule
AuthenticateRequest
HttpModule
AuthorizeRequest
www.synechron.com
In ASP.NET, we normally use outputcache directive to do caching. In this event, ASP.NET runtime determines HttpModule ResolveRequestCache if the page can be served from the cache rather than loading the patch from scratch. Any caching specific activity can be injected here. This event signals that ASP.NET runtime is ready to acquire session variables. HttpModule AcquireRequestState Any processing you would like to do on session variables. This event is raised just prior to handling control to the HttpHandler. HttpModule PreRequestHandlerExecute Before you want the control to be handed over to the handler any preprocessing you would like to do. Httphandler logic is executed. In this HttpHandler ProcessRequest section, we will write logic which needs to be executed as per page extensions.
An SEI CMMI Level 3 Company
www.synechron.com
Page
Init
Page
Load
Page
Validate
Render
This event happens in the ASP.NET page and can be used for: Creating controls dynamically, in case you have controls to be created on runtime. Any setting initialization. Master pages and the settings. In this section, we do not have access to viewstate, postedvalues and neither the controls are initialized. In this section, the ASP.NET controls are fully loaded and you write UI manipulation logic or any other logic over here. If you have valuators on your page, you would like to check the same here. Its now time to send the output to the browser. If you would like to make some changes to the final HTML which is going out to the browser, you can enter your HTML logic here.
www.synechron.com
Page HttpModule
Unload PostRequestHandlerExecute
Page object is unloaded from the memory. Any logic you would like to inject after the handlers are executed. If you would like to save update some state variables like session variables. Before you end, if you want to update your cache.
HttpModule HttpModule
ReleaserequestState UpdateRequestCache
HttpModule
EndRequest
This is the last stage before your output is sent to the client browser.
www.synechron.com
Seq
1 2 3 4
Events
Init Load view state PostBackdata Load
Controls Initialized No
5
6 7 8 9 10
Validate
Event Pre-render Save view state Render Unload
Yes
Yes Yes Yes Yes Yes
Yes
Yes Yes Yes Yes Yes
Yes
Yes Yes Yes Yes Yes
www.synechron.com