ASP.NET dynamically compiles the page. The output of the pages is generated dynamically. ASP.Net pages and application is processed and instantiated
The ASP.NET life cycle is divided into two categories
- Application Life cycle
- Page Life cycle
Application Life Cycle
There are series of steps that are launched to carry out the application process.
Application Start- The life cycle starts when the user first time clicks on the page. When the user requests the resource page. The browser sends request to the webserver. There is a method known as Application start which is executed by the webserver. This method has all global variables that are declared and set with default values.
Object Creation - This stage creates HTTPContext, HTTPRequest and HTTPResponse. HTTPContext is the container for HTTP Request and HTTP Response. The HTTP Request consists of information about the browser, cookies, and current requests. While the HTTP response consists of the response which will be sent to the user.
HTTP Creation – The object is being created by the webserver. This object is used to process the request sent to the application. For example- if we have multiple applications like online shopping applications, new related applications, etc. So, for each application, we will have a different HTTP Application object is created.
Dispose- In this stage, we release all unmanaged resources. Event is called before application instance is destroyed.
Application End- This is the final part of the application in which the application is unloaded from the memory.
Page Life cycle
- Page Request – This request is sent to the server. When page requests, the server checks if the request is made for the first time by the user. The response is sent back to the user if the user is not requesting for the first time then the output of the page is sent to the user.
- Page Start- In this stage request and response objects are created. The request is the object which was sent when the page was requested. The response is the object which is used to hold information and which is sent back to the user.
- Page initialization - In this stage controls on the webpage are initialized which means all the controls present on this page are initialized which can be textbox, label, etc.
- Page Load This stage is loaded with all default values of the controls. Values are loaded at the runtime.
- Validation There are some sets of validation rules in the form. For example, if we have a textbox on the form for accepting a mobile number of the user and the rule is set as text box limit to only 10 digits and has to be numeric.
- Postback event handling – This event is called when the same page is loaded again. Suppose we have a submit button on the page and on clicking submit the user will be brought back to the same page in such a scenario postback events are called.
- Page Rendering - All the information on the form is saved and the result is sent to the user as the complete webpage.
- Unload – once the page rendering is complete and a response has been sent to the user. It’s time to dispose of / release all ASP.NET web objects from the memory.