Asp.Net page life cycle events

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.

SharePoint deveopment training course

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:
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.

Init:
Raised after all controls have been initialized and any skin settings have been applied. Use this event to read or initialize control properties.

InitComplete:
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.

PreLoad:
Raised after the page loads view state for itself and all controls.

Load:
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.

Control events:
Use these events to handle specific control events, such as a Button control’s Click event or a TextBox control’s TextChanged event.

LoadComplete:
This event is fired when the page is completely loaded. Place code here that requires everything on the page to be loaded.

PreRender:
Use the event to make final changes to the contents of the page or its controls before the rendering stage begins.

PreRenderComplete:
Raised after each data bound control whose DataSourceID property is set calls its DataBind method.

SaveStateComplete:
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.

Render:
This is not an event; instead, at this stage of processing, the Page object calls this method on each control.

Unload:
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.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →