Have you ever wondered the first page event that is executed when you access a web page? If you are like me, then you will be curious to know everything that happened around you and things that you are using.
In this ASP.Net article, I am going to walk you through all you need to know about ASP.Net Application Life Cycle and ASP.Net Page Life Cycle.
ASP.Net life cycle is divided into different stages which are further called series.
Each time a request is made to the web server hosting the asp.net application, the application undergo a life cycle in which it performs a series of steps. These series include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering.
Given below is a detailed different stages of ASP.Net life cycle and their brief description.
The application start is the first of the series of the asp.net life cycle. This can only be activated if you make request to the web server hosting the ASP.Net application. Also, in this stage, all global variables are set to their default values.
After the first stage, the next stage is the object creation. In the object creation stage, the web server creates HttpRequest, HttpContext and HttpResponse.
Key Points to Note in object creation
The HttpContext is the container for the HttpRequest and HttpResponse objects.
The HttpRequest object holds information about the current request such as browser information and cookies.
While the HttpResponse object contains the response that is sent to the client.
Every subsequent request sent to the ASP.Net application is processed by HttpApplication Creation object. This object is created by the web server.
Every website hosted on a web server has its own HttpApplication creation object.
The Dispose is used to free or released all unmanaged resources.
Application End
This part is fired when IIS is restarted or shut down. This can also occurred when ASP.Net worker process is terminated.
When an ASP.Net page is called, it goes through a particular lifecycle. This is done before the response is sent to the user. There are series of steps which are followed for the processing of an ASP.Net page.
Described below is the list of asp.net page life cycle that occurs throughout life of the asp.net page.
Page Request
This simply means the first time the page is requested. Each time a page is requested from a web server, the web server does two things: (1) Check to see if the page is being requested before. If it has, then it checked for the cache version of the page then send it to the requesting user. (2) If the page has not been previously requested, it then compile the page, parse the response and send to the requesting user.
Page Start
During this time, 2 objects, known as the Request and Response object are created. The Request object is used to hold all the information which was sent when the page was requested. The Response object is used to hold the information which is sent back to the user.
Page Initialization
In page initialization, controls such as textbook, image, label e.t.c that are contained on the page are initialize.
Page Load
On page load, all default values are loaded into memory. That is why you will see any text or caption specified for the any control on a page will be loaded.
Validation
The validation is used to specify criteria that must be met before a particular action can take place on the form.
The postback event handling s triggered when a page is being reloaded. A very simplified example is when you clicked on a button on a page and still remain on that page.
When a user request for a particular page, the page rendering event is triggered, all information that makes up the form are saved while the result is sent to the user.
##What is Unload – Once the page output is sent to the user, there is no need to keep the ASP.net web form objects in memory. So the unloading process involves removing all unwanted objects from memory.