ASP.NET Application Life Cycle There are different stages of the application life cycle. They are explained as follows: Request is made to the application resource - The ASP.NET application life cycle starts by sending a request to the web server through a browser. The request pipeline is separate from the web server pipeline. The RequestNotification enumeration contains the stages. The pipeline receives the request for the application - Once the request is received, the instance of the Application Manager class is created. The domain provides isolation between global variables and individual application. Response object for every request is created - The application domain is created, object is instantiated, and the application objects are created and initialized. The HttpRequest object consist of information about the current request. HttpResponse object contains response sent to the client containing output and cookies. HttpContext class consists of objects related to the current application request. HttpApplication object is assigned to the request - Once all the objects are initialized, the instance of the Application class is created. The application creates an instance of the Global.asax class. The request is processed - The HttpApplication object processes the request assigned through the pipeline. Various events are raised using the class for processing the request. ASP.NET Page Life Cycle When a page executes it passes through life cycle and series of steps are performed. When user requests for a page, it is loaded in the memory. Processing is performed and the result is sent to the browser. Later it is unloaded. A hierarchical tree structure of the page is created. The components are page directives. The page life cycle has several phases which are explained below: Page request: It occurs before the life cycle starts. Once the user requests for the page, ASP.NET checks that the page needs to be parsed and compiled. Start of Page: The Request and Response objects are set. The page checks whether request is postback or new request. The IsPostBackProperty is set. Page Initialization: The controls on the page are associated with a unique ID. The ID is applied to the themes. Page Load: The properties of the control are set through the view and control state values. Validation: The Validate method of all the validator controls is called. The IsValid property of the validator control for the page is set. Postback event handling: Once the request is postback, event handlers are called. Rendering: The view state for all the controls is saved. The Page calls the Render method for every control. Unload: Once the page is fully rendered, the unload method is called. Page Life Cycle Events Page life cycle has events at every stage. An event handler is a function or subroutine that is bounded with an event. The page supports auto wire-up event. ASP.NET automatically executed the methods when the event is raised. The AutoEventWireup attribute of the @Page directive is set to true. The events for the Page life cycle are as listed below: PreInt: The first event in the page life cycle is PreInit. The IsPostback property is used to check the page is postback. The themes, master pages, dynamic controls, profile property values can be set. Init: Once all the controls are initialized, the event is raised. User can read and initialize the property. InitComplete: It is raised by the Page object. The task which needs the initialization to be completed. PreLoad: The event is used for performing the page processing on the page before the control is loaded. Load: The OnLoad event is called and is processed for the child controls till the page and controls are loaded. LoadComplete: The events for tasks need the controls on the page to be loaded. PreRender: The event occurs before the output is rendered. The pages and controls can perform updates before output is rendered. PreRenderComplete: The PreRender event is fired for the child controls. SaveStateComplete: The state of the control is saved. The control and view state information is saved. HTML markup is generated. The Render method is overridden. UnLoad: It is the end phase of the cycle. The Unload event is raised for all the controls. The clean action is performed for all references, resources, database connections. The OnUnLoad method is modified.