Tuesday, August 20, 2013

Filled Under:

ASP.NET Application and Page life cycle

Hi Friends, 

Welcome in DotNet Developers Cafe. This is my first post. So, read it and enjoy...



The ASP.Net life cycle could be divided into two groups:
  1. Application Life Cycle
  2. Page Life Cycle
ASP.Net Application Life Cycle:
The application life cycle has the following stages:
  • User makes a request for accessing application resource, a page. Browser sends this request to the web server.
  • A unified pipeline receives the first request and the following events take place:
    • An object of the ApplicationManager class is created.
    • An object of the HostingEnvironment class is created to provide information regarding the resources.
    • Top level items in the application are compiled.
  • Response objects are created . the application objects: HttpContext, HttpRequest and HttpResponse are created and initialized.
  • An instance of the HttpApplication object is created and assigned to the request. The request is processed by the HttpApplication class. Different events are raised by this class for processing the request.
ASP.Net Page Life Cycle:
When a page is requested, it is loaded into the server memory, processed and sent to the browser. Then it is unloaded from the memory. At each of this steps, methods and events are available, which could be overridden according to the need of the application. In other words, you can write your own code to override the default code.
The Page class creates a hierarchical tree of all the controls on the page. All the components on the page, except the directives are part of this control tree. You can see the control tree by adding trace= "true" to the Page directive. We will cover page directives and tracing under 'directives' and 'error handling'.
The page life cycle phases are:
  • Initialization
  • Instantiation of the controls on the page
  • Restoration and maintenance of the state
  • Execution of the event handler codes
  • Page rendering
Understanding the page cycle helps in writing codes for making some specific thing happen at any stage of the page life cycle. It also helps in writing custom controls and initializing them at right time, populate their properties with view-state data and run control behavior code.
Following are the different stages of an ASP.Net page:
  • Page request . when ASP.Net gets a page request, it decides whether to parse and compile the page or there would be a cached version of the page; accordingly the response is sent

  • Starting of page life cycle . at this stage, the Request and Response objects are set. If the request is an old request or post back, the IsPostBack property of the page is set to true. The UICulture property of the page is also set.

  • Page initialization . at this stage, the controls on the page are assigned unique ID by setting the UniqueID property and themes are applied. For a new request postback data is loaded and the control properties are restored to the view-state values.

  • Page load . at this stage, control properties are set using the view state and control state values.

  • Validation . Validate method of the validation control is called and if it runs successfully, the IsValid property of the page is set to true.

  • Postback event handling . if the request is a postback (old request), the related event handler is called.

  • Page rendering . at this stage, view state for the page and all controls are saved. The page calls the Render method for each control and the output of rendering is written to the OutputStream class of the Page's Response property.

  • Unload . the rendered page is sent to the client and page properties, such as Response and Request are unloaded and all cleanup done.
ASP.Net Page Life Cycle Events:
At each stage of the page life cycle, the page raises some events, which could be coded. An event handler is basically a function or subroutine, bound to the event, using declarative attributes like Onclick or handle.
Following are the 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 sets the themes and master pages, creates dynamic controls and gets and sets profile property values. This event can be handled by overloading the OnPreInit method or creating a Page_PreInit handler.
  • Init . Init event initializes the control property and the control tree is built. This event can be handled by overloading the OnInit method or creating a Page_Init handler.
  • InitComplete . InitComplete event allows tracking of view state. All the controls turn on view-state tracking.
  • LoadViewState . LoadViewState event allows loading view state information into the controls.
  • LoadPostData . during this phase, the contents of all the input fields defined with the <form> tag are processed.
  • PreLoad . PreLoad occurs before the post back data is loaded in the controls. This event can be handled by overloading the OnPreLoad method or creating a Page_PreLoad handler.
  • Load . the Load event is raised for the page first and then recursively for all child controls. The controls in the control tree are created. This event can be handled by overloading the OnLoad method or creating a Page_Load handler.
  • LoadComplete . the loading process is completed, control event handlers are run and page validation takes place. This event can be handled by overloading the OnLoadComplete method or creating a Page_LoadComplete handler.
  • PreRender . the PreRender event occurs just before the output is rendered. By handling this event, pages and controls can perform any updates before the output is rendered.
  • PreRenderComplete . as the PreRender event is recursively fired for all child controls, this event ensures the completion of the pre-rendering phase.
  • SaveStateComplete . state of control on the page is saved. Personalization, control state and view state information is saved. The HTML markup is generated. This stage can be handled by overriding the Render method or creating a Page_Render handler.
  • UnLoad . the UnLoad phase is the last phase of the page life cycle. It raises the UnLoad event for all controls recursively and lastly for the page itself. Final cleanup is done and all resources and references, such as database connections, are freed. This event can be handled by modifying the OnUnLoad method or creating a Page_UnLoad handler.

If you like this post share it.. If you encounter any problems, feel free and comment below to find solution. Share Your Experience with us.





41 comments:

  1. Hi Admin,
    This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
    Regards,
    Angularjs training in chennai|Node JS training|Python Training in Chennai

    ReplyDelete
  2. Excellent Post, I welcome your interest about to post blogs. It will help many of them to update their skills in their interesting field.
    Regards,
    Python Training in Chennai|Python training courses|Python training in velachery

    ReplyDelete
  3. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
    Data Science Training in Chennai
    Data science training in bangalore
    Data science online training
    Data science training in pune

    ReplyDelete
  4. I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.
    java training in chennai | java training in bangalore

    java training in tambaram | java training in velachery

    java training in omr

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Have you been thinking about the power sources and the tiles whom use blocks I wanted to thank you for this great read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out the new stuff you post
    python training in OMR
    python training in tambaram
    python training in annanagar

    ReplyDelete
  7. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 
    DevOps online Training
    Best Devops Training institute in Chennai

    ReplyDelete
  8. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...

    Selenium online Training | Selenium Training in Pune | Selenium Training in Bangalore

    ReplyDelete
  9. Please let me know if you’re looking for an author for your site. You have some great posts, and I think I would be a good asset. If you ever want to take some of the load off,
    safety course in chennai

    ReplyDelete
  10. This is an awesome post. Really very informative and creative contents. These concept is a good way to enhance the knowledge.
    industrial course in chennai

    ReplyDelete
  11. I ‘d mention that most of us visitors are endowed to exist in a fabulous place with very many wonderful individuals with very helpful things.
    iosh course in chennai

    ReplyDelete
  12. Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts.

    ReplyDelete
  13. Learned a lot of new things from your post! Good creation and HATS OFF to the creativity of your mind. sap fico training in bangalore

    ReplyDelete
  14. Nice Article.very impressed for this informative
    ExcelR data analytics courses

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. Nice post I have been searching for a useful post like this on salesforce course details, it is highly helpful for me and I have a great experience with this, Salesforce Training Australia  

    ReplyDelete
  17. Nice Post! Thank you for sharing very good post, it was so Nice to read and useful to improve my knowledge as updated one, keep blogging.
    It’s great to come across a blog every once in a while that isn’t
    AWS training in chennai | AWS training in annanagar | AWS training in omr | AWS training in porur | AWS training in tambaram | AWS training in velachery

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.It was very informative one. Thanks for sharing
    Data Science Training In Chennai

    Data Science Online Training In Chennai

    Data Science Training In Bangalore

    Data Science Training In Hyderabad

    Data Science Training In Coimbatore

    Data Science Training

    Data Science Online Training

    ReplyDelete
  20. Awesome blog it's very nice and useful i got many more information it's really nice i like your blog

    AI Training in Hyderabad

    ReplyDelete
  21. I appreciate this piece of useful information. CourseDrill academy one of the best leading Training Institute, provides the best Online services with expert Team. For more information visit our site:
    Oracle Fusion HCM Training
    Workday Training
    Okta Training
    Palo Alto Training
    Adobe Analytics Training

    ReplyDelete
  22. Extremely overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one. Continue posting. A debt of gratitude is in order for sharing.360digitmg-data science course data science course in mysore

    ReplyDelete
  23. I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.data science course data science course in mysore

    ReplyDelete
  24. The life cycle of an ASP.NET application and page is very well explained. To better understand how their code interacts with the framework, developers can benefit from your analysis of phases and events. I look forward to reading your future enlightening blogs. Continue your wonderful effort! 🚀

    Data Analytics Courses in India

    ReplyDelete
  25. This post provides a clear and informative overview of the ASP.NET Application and Page life cycle, making it easy for developers to understand and work with these crucial concepts. Thank you for sharing this.
    Data Analytics Courses in Nashik

    ReplyDelete
  26. The ASP.NET application and page life cycle is well explained in this post, making it simple for developers to comprehend and use these fundamental ideas. I appreciate you sharing this.
    Data Analytics Courses in Agra

    ReplyDelete
  27. It's a valuable resource for developers, and I've already liked and tweeted it to share with my network.
    Digital marketing courses in illinois

    ReplyDelete
  28. Thanks for sharing valuable and incredible explanation on Application Life Cycle and Page Life Cycle.
    Digital Marketing Courses in Italy

    ReplyDelete