Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET page life cycle explanation

I was asked to explain the ASP.NET page life cycle in an interview some time back. I did explain it to him, but he was not satisfied with my answer. Could someone explain the life cycle to me please?

like image 539
Sharique Avatar asked Dec 10 '11 14:12

Sharique


People also ask

What is ASP.NET page life cycle explain?

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.

Which is correct ASP.NET page life cycle?

ASP.NET Page Life Cycle includes events PreInit, Init, InitComplete, OnPreLoad, Load, PostBack, LoadComplete, OnPreRender, OnSaveStateComplete, Render, and UnLoad.

What is the first event in ASP.NET page life cycle?

PreInit - PreInit is the first event in page life cycle. 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.

How does the page lifecycle of ASP NET MVC works?

The ASP.NET MVC Process. In a MVC application, no physical page exists for a specific request. All the requests are routed to a special class called the Controller. The controller is responsible for generating the response and sending the content back to the browser.


1 Answers

There are 10 events in ASP.NET page life cycle, and the sequence is:

  1. Init
  2. Load view state
  3. Post back data
  4. Load
  5. Validate
  6. Events
  7. Pre-render
  8. Save view state
  9. Render
  10. Unload

Below is a pictorial view of ASP.NET Page life cycle with what kind of code is expected in that event. I suggest you read this article I wrote on the ASP.NET Page life cycle, which explains each of the 10 events in detail and when to use them.

ASP.NET life cycle

Image source: my own article at https://www.c-sharpcorner.com/uploadfile/shivprasadk/Asp-Net-application-and-page-life-cycle/ from 19 April 2010

like image 156
Shivprasad Koirala Avatar answered Oct 05 '22 01:10

Shivprasad Koirala