ASP.NET Life cycle

Discussion in 'ASP.NET' started by MinalS, Jun 26, 2015.

  1. ASP.NET Application Life Cycle



    There are different stages of the application life cycle. They are explained as follows:
    1. 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.
    2. 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.
    3. 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.
    4. 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.
    5. 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:
    1. 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.
    2. Start of Page: The Request and Response objects are set. The page checks whether request is postback or new request. The IsPostBackProperty is set.
    3. Page Initialization: The controls on the page are associated with a unique ID. The ID is applied to the themes.
    4. Page Load: The properties of the control are set through the view and control state values.
    5. Validation: The Validate method of all the validator controls is called. The IsValid property of the validator control for the page is set.
    6. Postback event handling: Once the request is postback, event handlers are called.
    7. Rendering: The view state for all the controls is saved. The Page calls the Render method for every control.
    8. 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:
    1. 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.
    2. Init: Once all the controls are initialized, the event is raised. User can read and initialize the property.
    3. InitComplete: It is raised by the Page object. The task which needs the initialization to be completed.
    4. PreLoad: The event is used for performing the page processing on the page before the control is loaded.
    5. Load: The OnLoad event is called and is processed for the child controls till the page and controls are loaded.
    6. LoadComplete: The events for tasks need the controls on the page to be loaded.
    7. PreRender: The event occurs before the output is rendered. The pages and controls can perform updates before output is rendered.
    8. PreRenderComplete: The PreRender event is fired for the child controls.
    9. 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.
    10. 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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice