Sunday 10 March 2013

Asp .Net Page Life Cycle Events


At each stage of the page life cycle, the page raises some events, which could be coded. An event handler is basically a function or subroutine, bound to the event, using declarative attributes like Onclick or handle. Asp.Net 3.5 & 4.0 page life cycle has following events in sequence :

PreInit

It is is entry point of page life cycle. It checks IsPostBack property to check or recreate dynamic controls. In this we can set master pages dynamically & set and get profile property values.

Init

It is is raised after all controls of page are initilised and skin properties are set. It is used to read or initialise control properties.

InitComplete

This indicates that page is completely initialised.

Preload

This event is called before loading the page in the RAM(memory). If any processing on a control or on page is required we use it.

Load

This invokes the onload event of the page. In this we create connection to the database, get/set controls values and get/set view state values.

loadComplete

This indicates that page is completely loaded into memory.

Prender

we use this event to make final changes to the controls or page before rendering it to the browser.

SaveStateComplete

View state of each control is saved before this event occurs. If we want to change the view state of any control then we use this event. This event can not be used to change the other properties of the controls.

Render/PrenderComplete

This indicates that page is completely rendered to the browser.Before rendering, view state is saved for the page and all controls. During the rendering stage, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream object of the page's Response property.

Unload

The Unload event is raised after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and cleanup is performed.We can use this event for closing files & database connection. This event occurs for each control.

No comments:

Post a Comment