Events in a Web Forms Page Life Cycle

Tags: Web Forms, Interview Questions, ASP.NET

Review time!!   

Interviewers still like to ask this question so I'm going to go over it.

Web Forms Page Load Events

PreInit - Here  you can check if the page is a post back, but the controls cannot be checked.  You can use this event to set global properties.

Init - Use this event to read or write control properties.

InitComplete - If you need page or controls to be initialized before your logic fires, you can use InitComplete.

PreLoad - Perform processing before control is loaded. Viewstate gets initialized after this event.

Load - Control properties are loaded with info from the viewstate.

LoadComplete - Validation is executed.  Use this to execute logic after all controls are loaded.

PreRender - EnsureChildControls has been called.  Use this to make any changes to content before it gets turned into HTML.

SaveStateComplete - Viewstate has been saved at this point.

Now the page gets Rendered.  This is not an event but you may have overridden the Render method in a custom control, this is when it would be executed.

Unload - Page has been rendered.  You can't change the page content at this point.  You can use this event to do clean up like closing an open filestream. 

No Comments

Add a Comment