Events in the Asp.Net page lifecycle

Posted: February 6, 2013 in ASP.NET
Tags: , , , , , ,

so , hello my readers,

In this article i will explain the events that will occur when the asp.net page is requested .The requesting of an ASP.NET page triggers a sequence of events that encompass the page life cycle. The Web browser sends a post request to the Web server. The Web server recognizes the ASP.NET file extension for the requested page and sends the request to the HTTP Page Handler class. The following list is a sampling of these events, numbered in the order in which they are triggered.

It is very important for any developer to understand these basic events to make robust application.

1)Init Event:  ASP Page framework initialization.It is raised  after the  start stage  is completed and before initialiazation stage begains. It is  It has 3 sub events.

PreInit:  This is the entry point of the ASP.NET page life cycle – it is the pre-initialization, so you have access to the page before it is initialized. Controls can be created within this event. Also, master pages and themes can be accessed. You can check the IsPostBack property here to determine if it is the first time a page has been loaded.

Init:  The Init event of individual controls occurs before theIinit event of the page. Use this event to read or initialize control properties.

Init complete:

Raised at the end of the page’s initialization stage. Only one operation takes place between the Init and InitComplete events: tracking of view state changes is turned on. View state tracking enables controls to persist any values that are programmatically added to the ViewState collection. Until view state tracking is turned on, any values added to view state are lost across postbacks. Controls typically turn on view state tracking immediately after they raise their Init event.

Use this event to make changes to view state that you want to make sure are persisted after the next postback.22

2)Load event : It has 3 events PreLoad, Load & LoadComplete

  • PreLoad:Raised after the page loads view state for itself and all controls, and after it processes postback data that is included with the Request instance. “View state load first then the Postback data”.
  • Load : The Load event of individual controls occurs after the Load event of the page. Use the OnLoad event method to set properties in controls and to establish database connections.
  • LoadComplete: This event is fired when the page is completely loaded. Place code here that requires everything on the page to be loaded.

3)Rendering: rendering simply means “To draw”.

  • PreRendering:This is the final stop in the page load cycle where you can make changes to page contents or controls. It is fired after all PostBack events and before ViewState has been saved. Also, this is where control databinding occurs.
  • RenderingComplete: This event is fired when PreRender is complete. Each control raises this event after databinding (when a control has its DataSourceID set).                                                                                                                    The PreRenderComplete event is raised when the pre-render stage of the page life cycle is complete. At this stage of the page life cycle, all controls are created, any pagination required is completed, and the page is ready to render to the output.This is the last event raised before the page’s view state is saved.

4) Save State Complete: State information for controls on the Web page is saved after the PreRenderComplete event. The SaveStateComplete event is raised after the view state and control state of the page and controls on the page are saved to the persistence medium.

5)Unload: This event fires for each control and then the page itself. It is fired when the HTML for the page is fully rendered. This is where you can take care of cleanup tasks, such as properly closing and disposing database connections.

so, here are the events !! Read it , understand it and let me know 🙂

Till then !! happy blogging 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s