ASP.NET architecture. We divide our discussion in two parts: the application life cycle events and the page life cycle events.
The Application Life Cycle Events
1. Whenever you press the Submit button on the web page, the request is sent to the web browser; in our case, let the web server be IIS.
2. The IIS picks up this request and looks for the server extensions. Each server extension is actually mapped to the IIS. Now, if the server extension of this request is .aspx, it maps to aspnet_isapi.dll. After this .dll is invoked, it hosts the ASP.NET worker process that initializes the Http Pipeline.
3. If the HttpApplication object does not exist for the application, it creates one—or else it picks it from the pool of these HttpApplication objects and passes the incoming request to it to handle.
4. The worker process calls the HttpRuntime.ProcessRequest() method.
5. The HttpRuntime creates the HttpContext and calls the HttpApplicationFactory.
6. The HttpApplicationFactory creates an instance of the web page object from a dynamically created assembly and selects the appropriate HttpApplication object that can serve the incoming request.
7. The HttpApplication instance processes the request and, in turn, selects the appropriate PageHandlerFactory.
8. The PageHandlerFactory now creates the page instance by making use of the page handler of the web page. It does this to return the page instance to the HttpRuntime through the HttpApplicationFactory.
9. The HttpRuntime uses this page instance and calls the ProcessRequest() method of the web page.
10. The ProcessRequest() method first calls the FrameworkInitialize() method and then calls the page life cycle methods.
The sequence of events that are executed in the life cycle of an ASP.NET web page.
The Page Life Cycle Events
The sequence of events that are executed in the life cycle of a page.
The following are these events, listed in the order in which they are executed:
1. Page_Init
2. LoadViewState
3. LoadPostData
4. Page_Load
5. RaisePostDataChangedEvent
6. RaisePostBackEvent
7. Page_PreRender
8. SaveViewState
9. Page_Render
10. Page_UnLoad
These events can be overridden—that is, you can override them to implement your custom handlers—and are associated with their respective event handlers. The ASP.NET page life cycle events are discussed in the following steps:
1. The page life cycle starts with the invocation of the Page_Init event. This event is responsible for initializing the controls that you use in your page to their default values. This event can also be used to create or even re-create the controls in your web page that need to be created dynamically.
2. The next event handler that gets executed is the LoadViewState method that restores the View State for the web page. This method is only executed if and when the web page has been posted back and restores any previously stored View State data associated with the web page.
3. The next method to be executed in this chain of events is the LoadPostBackData. This method is responsible for processing the data of the server controls, and these controls are populated with the previously posted data.
4. The Page_Load event is triggered. This method can be used to populate and bind data to your controls either from the database or any other sources, states, and so on.
5. The RaisePostBackData and RaisePostBack events are triggered if, and only if, there was a postback. The PreRender event is fired next, and you can use this event to make any changes to the data contained in your controls prior to their rendering.
6. The Render event is triggered, which creates the Response object for the web page. Now the page is eventually rendered through the Render event, which uses a text writer to write the response stream to the Response.
7. The page is unloaded from the memory, and the Response object is sent to the browser in the Page Unload event. You can override this method to perform your necessary cleanup activities. According to MSDN, “Unload is called after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and any cleanup is performed.”
ASP.NET Architecture
Hot on Web: