Wednesday 10 June 2015

ASP.Net Page life cycle overview

When an ASP.Net page runs, the page goes through a life cycle in which it performs a series of processing steps. These includes
  • Initialization
  • Instantiating controls
  • Restroring and maintaining state
  • Running event handler code, and
  • Rendering
General page life cycle stages:
Some parts of the life cycle occur only when a page is processed as postback. For postbacks, the page life cycle is same during a partial postback(as when you use an Update Panel control) as it is during a full page postback.
  1. Page Request
  2. Start
  3. Initialization
  4. Load
  5. Postback event handling
  6. Rendering
  7. Unload
Stage
Description
Page request
The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.
Start
In the start stage, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. The page also sets the UICulture property.
Initialization
During page initialization, controls on the page are available and each control's UniqueID property is set. A master page and themes are also applied to the page if applicable. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.
Load
During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.
Postback event handling
If the request is a postback, control event handlers are called. After that, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page. (There is an exception to this sequence: the handler for the event that caused validation is called after validation.)
Rendering
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 andRequest are unloaded and cleanup is performed.
Why we need to learn ASP.Net Page life cycle?

If you develop custom controls, you must be familiar with tha page life cycle in order to correctly initialize controls, populate control behaviour code. The life cycle of a control is based on page life cycle, and the page raises many of the events that you need to handle in a custom control.

Event In which all controls are fully loaded in asp.net

             Page load event guarantees that all controls are fully loaded. Controls are also accessed in Page_Init event but you will see that view state is not fully loadedduring this event.

Reference:
http://msdn.microsoft.com/en-us/library/ms178472.aspx
http://stackoverflow.com/questions/8457297/asp-net-page-life-cycle-explanation
http://studentboxoffice.in/interviewquestion.aspx?id=39

2 comments:

  1. Super Blog, When i was read this blog i learnt lot of things & its truly have good stuff related to developing technology, Thank you so much for sharing this blog. Keep doing more blog like this.
    Dot Net Training And Placement in Chennai
    Java Training Institute in Chennai
    PHP Course in Chennai
    Software Testing Training in Chennai

    ReplyDelete
  2. I would like to say thank you for the amazing details and concepts you are sharing in this.The style of writing is excellent and also the content is top-notch. Thanks for that shrewdness you provide the readers! to read. I never stop myself to say something about it. You’re doing a great job. 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