Sunday 24 September 2017

ASP.NET Page Life Cycle Events

Pre Init:

  • Check for "IsPostBack" property to determine whether this is the first time the page is being processed.
  • Create or recreate dynamic controls.
  • Set master page dynamically & theme property also.
  • Read or set profile property values.
  • This event can be handled by overloading the OnPreInit method or creating the Page-PreInit handler.

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.
  • This event can be handled by overloading the OnInit method or creating a Page-Init handler.

InitComplete:

  • This event allows tracking of View State.
  • Raised at the end of the page's initialization stage.
  • View state tracking enables controls to persists any values that are programmatically added to the view state collection.
  • Untill 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.
  • Any changes made to the view state in this event are persisted even after the next postback.

PreLoad:

  • This event process 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.
  • This load event of the individual controls occurs after the load event of the page.

Control Events:

  • This event is used to handle specific control events such as button control's click event or a textbox control's TextChanged event.

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:

  • PreRender event of the pageis called first and later for the child controls.
  • This event is used to make the final changes to the controls on the page like assigning the DataSourceID and calling the DataBind Method.
  • Prerender event occurs just before the output is rendered.
  • By handling this event, pages & controls can perform any updates before the output is rendered.

Prerender Complete:

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

SaveState Complete:

  • This event is raised after the control state & view state have been saved for the page and for all controls.
  • The HTML markup is generated.

Render Complete:

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

Unload:

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

No comments:

Post a Comment