Asp.Net page life cycle events
Check out Best Alternative to InfoPath -> Try Now
In this post, we will discuss Asp.Net page lifecycle events.
You can also check my previous posts on When to use Thread Pool class, Introduction to multithreading in C# and How to enable Prefetching for web applications in Windows server.
Within each stage of the life cycle of a page, the page raises events that you can handle to run your own code.
Below are page lifecycle events:
PreInit is the first event in page life cycle. It checks the IsPostBack property and determines whether the page is a postback. It creates or re-creates dynamic controls, also you can set the master page and theme dynamically.
Raised after all controls have been initialized and any skin settings have been applied. Use this event to read or initialize control properties.
Raised at the end of the page’s initialization stage. Use this event to make changes to view state that you want to make sure are persisted after the next postback.
Raised after the page loads view state for itself and all controls.
The page Load event occurs first followed by the Load event for all controls. This is where most coding is done, so you want to check the IsPostBack property to avoid unnecessary work.
Use these events to handle specific control events, such as a Button control’s Click event or a TextBox control’s TextChanged event.
This event is fired when the page is completely loaded. Place code here that requires everything on the page to be loaded.
Use the event to make final changes to the contents of the page or its controls before the rendering stage begins.
Raised after each data bound control whose DataSourceID property is set calls its DataBind method.
Raised after view state and control state have been saved for the page and for all controls. Any changes to the page or controls at this point affect rendering, but the changes will not be retrieved on the next postback.
This is not an event; instead, at this stage of processing, the Page object calls this method on each control.
Raised for each control and then for the page.
In controls, use this event to do final cleanup for specific controls, such as closing control-specific database connections.
For the page itself, use this event to do final cleanup work, such as closing open files and database connections, or finishing up logging or other request-specific tasks.
SharePoint Online FREE Training
JOIN a FREE SharePoint Video Course (3 Part Video Series)