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.





59 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. 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
  23. 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
  24. 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
  25. 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
  26. Thanks for sharing valuable and incredible explanation on Application Life Cycle and Page Life Cycle.
    Digital Marketing Courses in Italy

    ReplyDelete
  27. Nice Post! Thank you for sharing very good post, it was so Nice to read and useful to improve my knowledge making it simple for developers to comprehend and use these fundamental ideas. I appreciate you sharing this.
    Data science courses in Gurgaon

    ReplyDelete
  28. Great insights on the ASP.NET application and page life cycle! Understanding these phases is essential for optimizing performance and debugging effectively. Your breakdown of each stage makes it easy for developers to grasp the flow and improve their applications. Keep up the excellent work—your content is a valuable resource for the community!
    Data Science Courses in Singapore

    ReplyDelete
  29. I appreciate your insights, but I think it would be helpful to include some potential pitfalls to avoid in digital marketing. It’s always good to be aware of challenges!

    Data science courses in Gujarat

    ReplyDelete
  30. Very nice article about asp.net. It is well written and explained. It will be helpful to many software developers. Found it interesting to read and gained much information about the topic. Thank you for sharing.
    Data science courses in Kochi

    ReplyDelete
  31. thank you for sharing they make it much easier to understand. Looking forward to more posts like this
    Data science courses in Bhutan

    ReplyDelete
  32. Best explained on The ASP.Net life cycle. Very clear and easy to understand the whole concept.
    Online Data Science Course

    ReplyDelete
  33. The way you shared your idea on ASP.net application and page life cycle made my view more clear. Thanks for provideing such valuable details.
    Online Data Science Course

    ReplyDelete
  34. "I found this article on the Data Science Course in Dadar to be very enlightening!
    The course looks like it covers all the essential skills needed today.
    I’m particularly excited about the real-world projects.
    It’s fantastic to see quality education options available nearby!
    I’m definitely interested in enrolling!"

    ReplyDelete
  35. This article provides a detailed breakdown of the ASP.Net application and page life cycles, which is essential for developers aiming to optimize their web applications.
    Data science courses in Mysore

    ReplyDelete
  36. I really appreciate your vulnerability in sharing your experiences. It makes your writing feel authentic and allows readers to connect on a deeper level

    Data science courses in Mumbai

    ReplyDelete
  37. The post on Dotnet Developers Cafe about the ASP.NET application and page life cycle is very informative! It provides a clear breakdown of the different stages, helping developers understand how their applications process requests. The detailed explanations and visuals enhance comprehension, making it a great resource for both beginners and experienced developers. Thanks for sharing such valuable insights!

    Data science courses in Bangalore.

    ReplyDelete
  38. The ASP.NET Application and Page Life Cycle are crucial for understanding how ASP.NET processes and renders web pages. The Application Life Cycle manages the application's start, request handling, and end, while the Page Life Cycle handles individual pages, including stages like initialization, loading, events, rendering, and unloading.
    Data science Courses in Germany

    ReplyDelete
  39. If you’re ready to take charge of your career and dive into the world of data science, now’s the time! The courses featured in this post will give you the knowledge and skills to succeed in this exciting and ever-evolving field. Check out the list of courses available in Iraq here. Your future in data science starts now!

    ReplyDelete
  40. Great explanation of the ASP.NET application and page life cycle! It’s very clear and helpful, especially for developers looking to understand the underlying flow of an ASP.NET application. I appreciate the detailed breakdown of each step—this will definitely be a valuable reference for anyone working with ASP.NET.
    Data science course in Gurgaon

    ReplyDelete
  41. Thank you for this comprehensive post on the ASP.NET application and page life cycle! Your clear breakdown of each stage is incredibly helpful for developers aiming to deepen their understanding of the framework.
    Data science course in Lucknow

    ReplyDelete
  42. You have explained The ASP.Net application in a nice way. thank you for this article.

    Data science courses in chennai

    ReplyDelete
  43. Thank you for this detailed explanation of the ASP.NET application and page life cycle! It's a great resource for developers to understand the internal workings and flow of an ASP.NET application. Your clear breakdown makes complex concepts much easier to grasp!
    Data science courses in Bangladesh

    ReplyDelete
  44. Informational blog. i found this blog very informational and intresting.

    technical writing course

    ReplyDelete
  45. Great post! This clear explanation of the ASP.NET Application and Page Life Cycles is really helpful for both beginners and experienced developers. Understanding these stages is key to optimizing performance and writing efficient code. Looking forward to more insights! Investment Banking Course

    ReplyDelete