ASP.NET Page Life Cycle

What is ASP.NET Life Cycle?

It is the process which defines that how ASP.NET pages process to produce dynamic output. And it also specifies how ASP.NET compiles the pages dynamically.

ASP.NET life cycle is divided into two groups:

i) Application Life Cycle

ii) Page Life Cycle

i) Application Life Cycle

The application life cycle starts when a user makes a request. And that request contains several states and these stages are: application life cycle, application life cycle overview, application life cycle stages, application life cycle diagram

  • Application Start: It is a method that can be executed by the web server when a user makes a request.

  • Object Creation: The HTTP requests contain all the information about the content request, like cookies, and browser information.

  • HTTP Application: It is an object which helps to process each subsequent request sent to the application that is created by the web browser.

  • Dispose: It is an event that can be called before the application is destroyed. And Dispose helps to release manually unmanaged resources.

  • Application End: This stage of the Application Life Cycle helps to unload the memory.

ii) Page Life Cycle

ASP.NET Page Life Cycle has some specific steps that are carried out during the execution. These phases include initialization, restoring, execution, etc. And ASP.NET page goes through these from the time it is requested by a user to the point at which the page is fully rendered in the user's browser

The number of sequential events takes place whenever a page is requested.

The events include initialization, Instantiating controls, restoring and maintaining state, running event handler code, and rendering. page life cycle, page life cycle diagram

  • Page Request: When the user requests a page, the server checks the request and then compiles the page.

  • Page Start: In this phase, the two steps are carried out first is "request" and second is"response". The request holds all information from the page.

  • Page Initialization: In this phase, all the controls on the page are set, and each has a particular ID, and themes are applied to the pages.

  • Page Load: In Page Load, all the control properties are loaded, and information is set using view state and control state.

  • Validation: The validation happens when the page execution goes successful it returns true else the execution fails it returns false.

  • Event Handling: This happens in response to validation. In this case, the page is loaded again. So, the postback event handler is called.

  • Rendering: It occurs before all the response information is sent to the user. It also stores all the information sent to the user.

  • Unload: This phase helps to clean all the unwanted information. And it also cleans the memory once the page output is sent to the user.

Page Life Cycle Stages

  • PreInit: It is the first event in the page life cycle. And it checks the IsPostBack property and determines whether the page is a postback. It sets the themes and master pages, creates dynamic controls, and gets and sets profile property values. The PreInit event can be handled by overloading the OnPreInit method.

  • Init: This event is used to initialize the control property and the control tree is built. The Init event can be handled by overloading the OnInit method or creating a Page_Init handler.

  • InitComplete: This event allows tracking of the view state. And it controls turn-on view-state tracking. The InitComplete event can be used to make changes in ViewState.

  • PreLoad: This event is raised when the page loads the ViewState. And it Loads the PostBack data.

  • Load: The page's load event is raised first, followed by recursively raising all child controls' load events. The control tree's controls are made. The OnLoad method can be overloaded to handle this event, or a Page Load handler can be made.

  • Control Events: It is used to handle specific control events such as Button control' Click event.

  • LoadComplete: LoadComplete event occurs at the end of the event-handling stage. We can use this event for tasks that require all other controls on the page to be loaded.

  • PreRender: This event takes place just before the output is rendered. By handling this event, pages, and controls can perform any updates before the output is rendered. This event occurs after the page object has created all controls that are required in order to render the page.

  • PreRenderComplete: This event is triggered recursively for all child controls, make sure that the pre-rendering phase is completely done. This event happens once each data-bound control with its DataSourceID property set calls the DataBind method.

  • SaveStateComplete: The SaveStateComplete is raised after the view state and the control state have been saved for the page and for all controls.

  • Render: This is not an event; rather, the Page object calls this method on each control at this step of processing.

  • Unload: This is the last event and it is raised for each control and then for the page. It can be handled by modifying the OnUnLoad method.


Post a Comment

* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Top Post Ad

Below Post Ad

Ads Section