Powered by Blogger.

Saturday, March 1, 2014

Asp.Net page life cycle evets




In this post we will discuss about Asp.Net page life cycle events.

You can also check sme posts on:

- Redirect to different page using jQuery in Asp.Net

- How to implement FileUpload Control in Update Panel using asp.net?

- Sealed class and Sealed method in C#.Net

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 life cycle 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 create or re-create dynamic controls, also you can set 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.



0 comments

Post a Comment