The page life cycle in ASP.NET is the sequence of events that occur when a web page is requested and rendered. The page life cycle consists of the following stages:
1. Pre-Init: This stage is triggered when the page is first requested. It performs any initializations that are required before the page can be processed.
2. Init: This stage initializes the page and its controls. It also creates the page’s control hierarchy and sets the page’s properties.
3. Load: This stage loads the page’s view state and control state.
4. Post-Back Event Handling: This stage handles any post-back events that are triggered by the user.
5. Pre-Render: This stage is triggered before the page is rendered. It allows any final adjustments to be made before the page is displayed.
6. Render: This stage renders the page’s output.
7. Unload: This stage is triggered after the page has been rendered. It cleans up any resources that were used during the page’s life cycle.
For example, when a user requests a page, the Pre-Init stage is triggered. This stage initializes any required resources before the page can be processed. Once the page is initialized, the Init stage is triggered. This stage creates the page’s control hierarchy and sets the page’s properties. The Load stage is then triggered, which loads the page’s view state and control state. After the page is loaded, any post-back events triggered by the user are handled in the Post-Back Event Handling stage. Finally, the Pre-Render, Render, and Unload stages are triggered in sequence to render the page and clean up any resources that were used during the page’s life cycle.