Wednesday 7 August 2013

ASP.NET Page Life Cycle Events || What is the sequence in which ASP.NET events are processed? Interview Questions on ASP.NET

Hi friends, in this article I will explain about ASP.NET Page Life Cycle Events or what is the sequence in which ASP.NET events are processed?
In previous article i already explained Interview Questions on SQL SERVER Part I | Interview Questions and Answers on SQL SERVER Part I ,Interview Questions in VB.NET, .NET Framework. and ASP.NET interview Questions .
ASP.NET life cycle is as follows


The following events will occur in the ASP.NET:
1. PreInit
  • It will raised after the start stage is complete and before the initialization stage begins.
  • For checking that whether the page has been processed first time or PostBack.
  • Master pages can be called dynamically.
  • Themes can be set dynamically.
  • Programmatically add controls to controls collection it.
 2.Init
  • It will raised after all controls have been initialized.
  • In this event you can read or initialize control properties.
 3.InitComplete
  • Raised at the end of the page's initialization stage.
  • If you want to do some tasks after Init event than you can use this event .
4.PreLoad
  • Raised after the page loads ViewState  for itself and all controls, and after it processes postback data that is included with the Request instance .If you want to do some processing before Load event, use this event. ViewState loading for all controls and processing of Postback data has been done before the Page instance raises this event.
5.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. This event kicks in after the controls have been initialized with their correct values. 
  • This processing has been done recursively for each child control, which does the same for each of its child controls until the page and all controls are loaded.
6.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. 
  • Any events that results from the user interacting with controls, such as when user clicks a button or selects an item from a dropdown list, are raised after the Load event.
 7.LoadComplete
  • Raised at the end of the event-handling stage. 
  • Use this event for tasks that require that all other controls on the page be loaded.
 8.PreRender
  • Raised after the Page object has created all controls that are required in order to render the page, including child controls of composite controls. 
  • This event is raised after all of the control events have been raised but before the HTML, that will be sent back to the browser is generated. The PreRender event occurs for each control on the page.
  •  Use the event to make final changes to the contents of the page or its controls.
9.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.
  •  Before this event occurs, ViewState has been saved for the page and for all controls. Any changes to the page or controls at this point will be ignored. 
  • Use this event perform tasks that require view state to be saved, but that do not make any changes to controls.
 10.Render
  • This is not an event; instead, at this stage of processing, the Page object calls this method on each control. All ASP.NET Web server controls have a Render method that writes out the control's markup to send to the browser. 
  • The Render event commences the building of the page by assembling the HTML for output to the browser. During the Render event, the page calls on the objects to render them into HTML. 
  • The page then collects the HTML for delivery. When the Render event is overridden, the developer can write custom HTML to the browser.
11.Unload
  • Raised for each control and then for the page. 
  • This event is raised when the page has been sent back to the browser. This event occurs for each control and then for the page.
The below figure shows how the above events occurs at what time.

No comments:

Post a Comment

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.