Thursday, 4 September 2014

ASP .Net Page Life Cycle Events


ASP .Net Page Life Cycle Events:


PreInit:

You can:
  • Check for the IsPostBack property to determine whether this is the first time the page is being processed.
  • Create or recreate dynamic controls.
  • Set master page dynamically.
  • Set the Theme property dynamically.
  • Read or set profile property values.
If Request is postback:
  • The values of the controls have not yet been restored from view state.
  • If you set control property at this stage, its value might be overwritten in the next event.

Init:

  • In the Init event of the individual controls occurs first, later the Init event of the Page takes place.
  • This event is used to initialize control properties.

InitComplete:

  • Tracking of the ViewState is turned on in this event.
  • Any changes made to the ViewState in this event are persisted even after the next postback.

PreLoad:

  • This event processes the postback data that is included with the request.

Load:

  • In this event the Page object calls the OnLoad method on the Page object itself, later the OnLoad method of the controls is called.
  • Thus Load event of the individual controls occurs after the Load event of the page.

ControlEvents:

  • This event is used to handle specific control events such as a Button control’s Click event or a TextBoxcontrol’s TextChanged event.
In case of postback:
  • If the page contains validator controls, the Page.IsValid property and the validation of the controls takes place before the firing of individual control events.

LoadComplete:

  • This event occurs after the event handling stage.
  • This event is used for tasks such as loading all other controls on the page.

PreRender:

  • In this event the PreRender event of the page is called first and later for the child control.
Usage:
  • This method is used to make final changes to the controls on the page like assigning the DataSourceId and calling the DataBind method.

PreRenderComplete:

  • This event is raised after each control's PreRender property is completed.

SaveStateComplete:

  • This is raised after the control state and view state have been saved for the page and for all controls.

RenderComplete:

  • The page object calls this method on each control which is present on the page.
  • This method writes the control’s markup to send it to the browser.

Unload:

  • This event is raised for each control and then for the Page object.
Usage:
  • Use this event in controls for final cleanup work, such as closing open database connections, closing open files, etc.

49 comments:

  1. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.
    biztalk-training-in-chennai

    ReplyDelete
  2. This blog gives very important info about .Net Thanks for sharing
    .Net Online Training

    ReplyDelete
  3. Thanks for sharing your valuable information and time.
    PHP Training in Delhi
    PHP Training institute in Delhi

    ReplyDelete
  4. wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries. keep it up.


    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery

    ReplyDelete