Вы находитесь на странице: 1из 3

7/18/13

ASP.NET Page Life Cycle

In Focus

Delhi Chapter July Meet : Enterprise Architect, ASP.NET Web API, AJAX, MVC and JavaScript

Ask a Question
TECHNOLOGIES ANSWERS BLOGS VIDEOS INTERVIEWS BOOKS LINKS NEWS CHAPTERS CAREER ADVICE

Contribute

5 Tips to Improve Performance of C# Code

C# Corner Search

PREMIUM SPONSORS

ARTICLE
230
Tw eet

Infragistics
Infragistics is experts in technology and design, and passionate about helping you build highly performant and stylish applications that solve problems, deliver inspiration, and maximize results.

ASP.NET Page Life Cycle


Posted by Santhi Maadhaven in Articles | Web Development on March 04, 2005 Tags: ASP.NET, ASP.NET Events, ASP.NET Page Execution, ASP.NET Page Life Cycle, ASP.NET Stages, C# In this article, we will see the stages of execution of the ASP.NET Page.
Share 0 Like 24

360
0

215589

0 In this article, we will see the stages of execution of the ASP .NET Page.

Reader Level:

Each request for an .aspx page that hits IIS is handed over to HTTP Pipeline. HTTP Pipeline is a chain of managed objects that sequentially process the request and convert it to plain HTML text content. The start point of HTTP Pipeline is the HttpRuntime class. The ASP.NET infrastructure creates each instance of this class per AppDomain hosted within the worker process. HttpRuntime class picks up an HttpApplication object from an internal pool and sets it to work on the request. It finds out what class has to handle the request. The association between the resources and handlers are stored in the configurable file of the application. In web.config and also in machine.config you will find these lines in <httpHandlers> section. If you run through the following program, it will be much easier to follow <add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory"/> This extension can be associated with HandlerClass or HandlerFactory class. HttpApplication object gets the page object that implements the IHttpHandler Interface. The process of generating the output to the browser is started when the object calls ProcessRequest method. Page Life Cycle Once the HTTP page handler class is fully identified, the ASP.NET runtime calls the handler's ProcessRequest to start the process. This implementation begins by calling the method FrameworkInitialize(), which builds the control trees for the page. This is a protected and virtual member of TemplateControl class, class from which page itself derives. Next the processRequest() makes page transits various phases: initialization, loading of viewstate and postback data, loading of page's user code and execution postback server-side events. Then page enters in render mode, the viewstate is updated and HTML generated is sent to the output console. Finally page is unloaded and request is considered completely served. Stages and corresponding events in the life cycle of the ASP.NET page cycle: Stage Page Initialization View State Loading Postback data processing Page Loading PostBack Change Notification PostBack Event Handling Page Pre Rendering Phase View State Saving Page Rendering Page Unloading Events/Method Page_Init LoadViewState LoadPostData Page_Load RaisePostDataChangedEvent RaisePostBackEvent Page_PreRender SaveViewState Page_Render Page_UnLoad

TRENDING UP
5 Tips to Improve Performance of C# Code C# Corner Mumbai Chapter: Learn Windows Presentation Foundation (WPF) ASP.Net MVC - How to Post a Collection Failed to Create Term Set: A Default Managed Metadata Service Connection Hasnt Been Specified How To Make a Chat Application in C# Using CSS Pseudo-Class Best Practices - Exception Handling in C# .NET Create and Consume Web API in MVC 4 What is LINQ and Array Processing Using LINQ Feature Stapling in SharePoint

View All

MOST LIKED ARTICLE


WCF Introduction and Contracts - Day 1 Create SSRS Report Using Report Wizard CREATE READ UPDATE and DELETE - CRUD Operation Using LINQ to SQL WCF - Data Contract - Day 4 Factory Design Pattern
Follow @csharpcorner 4,788 follow ers

Some of the events listed above are not visible at the page level. It will be visible if you happen to write server controls and write a class that is derived from page. Page Execution Stages The first stage in the page life cycle is initialization. This is fired after the page's control tree has been successfully created. All the controls that are statically declared in the .aspx file will be initialized with the default values. Controls can use this event to initialize some of the settings that can be used throughout the lifetime of the incoming web request. Viewstate information will not be available at this stage. After initialization, page framework loads the view state for the page. Viewstate is a collection of

www.c-sharpcorner.com/UploadFile/Santhi.M/ASP.NETLifeCycle11282005043446AM/ASP.NETLifeCycle.aspx

1/3

7/18/13

ASP.NET Page Life Cycle


Find us on Facebook

name/value pairs, where control's and page itself store information that is persistent among web requests. It contains the state of the controls the last time the page was processed on the server. By overriding LoadViewState() method, component developer can understand how viewstate is restored. Once viewstate is restored, control will be updated with the client side changes. It loads the posted data values. The PostBackData event gives control a chance to update their state that reflects the state of the HTML element on the client. At the end of the posted data changes event, controls will be reflected with changes done on the client. At this point, load event is fired. Key event in the life cycle is when the server-side code associated with an event triggered on the client. When the user clicks on the button, the page posts back. Page framework calls the RaisePostBackEvent. This event looks up for the event handler and run the associated delegate. After PostBack event, page prepares for rendering. PreRender event is called. This is the place where user can do the update operations before the viewstate is stored and output is rendered. Next stage is saving view state, all the values of the controls will be saved to their own viewstate collection. The resultant viewstate is serialized, hashed, base24 encoded and associated with the _viewstate hidden field. Next the render method is called. This method takes the HtmlWriter object and uses it to accumulate all HTML text to be generated for the control. For each control the page calls the render method and caches the HTML output. The rendering mechanism for the control can be altered by overriding this render method. The final stage of the life cycle is unload event. This is called just before the page object is dismissed. In this event, you can release critical resources you have such as database connections, files, graphical objects etc. After this event browser receives the HTTP response packet and displays the page. Login to add your contents and source code to this article

C# Corner
Like 12,897 people like C# Corner.

F acebook social plugin

HOT KEYWORDS
.NET Classes .NET components ASP.NET Page Execution auto postback for combobox Display File stream HTTP handler MasterDetailedDisplay MemoryStream using a HTTP Handler Migration Modal Popup Modal Popup Dialog Window Modal Popup Dialog Window in ASP.NET Page directive Planning Popup Window PostBackData

Posting data from ASP.NET page to another URL RemotePost Class render
Shopping Cart tic tac toe game web form Web.config
file Windows Users

THIS FEATURE IS SPONSORED BY

ELEFLEX i s a n open-s ource, .NET C# enterpri s e a ppl i ca ti on fra mework for bui l di ng end-toend, hi gh performa nce, s ervi ce ori ented a rchi tecture (SOA) a ppl i ca ti ons wi th code genera ti on i n mi nd.

Performance Improvement in ASP.NET Using Caching

Tags: .NET caching, ASP.NET Caching, ASP.NET web pages caching, C#, Cache entry attributes, cache varying options, Caching

Tags: ASP.NET, C#, Code-Behind, Code-inline, Globalization, Globalization using ASP.NET, Resource Management

Globalization Using ASP.NET

SPONSORED BY
Get the industry leading .NET Diagramming component
.NET Diagramming framework designed for creating advanced solutions

RELATED ARTICLES
ASP.NET Page Life Cycle Events ASP.NET Page Life Cycle in VB.NET Understanding the Page Life Cycle of an ASP.NET and its controls Compilation Life cycle of Asp.Net 2.0 Web Site System Development Life Cycle: Part 2 ASP.Net 2.0 What's new in Page Life Cycle ASP.NET application and page life cycle HTTP Modules in ASP.NET Request life cycle Software Testing Life Cycle (STLC) Describing the JSP Page Life Cycle

COMMENTS
7 of 7 rajani shetty ok
0 Li ke 0 Repl y

May 24, 2007

Altaf Khatri Nice article. This article also describes sequential ASP.net page life cycle and events .
0 Li ke 0 Repl y

Sep 13, 2009

Dinesh Singh klkkjklklpplpopkopopoppop[opop


0 Li ke 0 Repl y

WHITEPAPERS AND BOOKS


Mar 20, 2010

Interview Questions on SharePoint 2013 SharePoint 2010 Administration & Development Getting Started with Managed Metadata Service in SharePoint 2010 Windows Phone 7 Hileleri Windows Phone Development Step by Step Tutorial Essentials of SharePoint 2010: Business Intelligence Capabilities Working with Directories in C# FileInfo in C# Programming List with C# Source Code: Graphics Programming with GDI+

Sami Akram I want to facilitate user to change the state of controls on web page permanently. e.g. if user checked a check-box, it should remain checked although user goes to other web page and comes back, until user him/herself makes it unchecked
0 Li ke 0 Repl y

May 30, 2010

sahi a Nice article.it helps me in interview as well:)


0 Li ke 0 Repl y

Dec 22, 2010

jatin nahar This is very helpful to me.......for better understanding of page life cycle you can visit following link.... http://dotnetpeoples.blogspot.com/2011/04/eventpage-life-cycle-in-aspnet.html
0 Li ke 0 Repl y

Apr 05, 2011

www.c-sharpcorner.com/UploadFile/Santhi.M/ASP.NETLifeCycle11282005043446AM/ASP.NETLifeCycle.aspx

2/3

7/18/13
suresh kumar nice article
0 Li ke 0 Repl y

ASP.NET Page Life Cycle

View All
Oct 14, 2011

POLL

RESULT

ALL POLLS

Type your comment here and press Enter Key....

Speed of C# Corner

COMMENT USING
Add a comment...

How do you find speed of C# Corner when visiting the site? Very Fast OK Slow Very Slow
Vote

Comment using...
F acebook social plugin

MVPs

MOST VIEWED

LEGENDS

NOW

PRIZES

AWARDS

REVIEWS

SURVEY

CERTIFICATIONS

DOWNLOADS

Hosted By CBeyond Cloud Services

PHOTOS

TIPS

CONSULTING

TRAINING

STUDENTS

MEMBERS

MEDIA KIT

SUGGEST AN IDEA

PRIVACY POLICY | TERMS & CONDITIONS | SITEMAP | CONTACT US | ABOUT US | REPORT ABUSE

2013 C# Corner. All contents are copyright of their authors.

www.c-sharpcorner.com/UploadFile/Santhi.M/ASP.NETLifeCycle11282005043446AM/ASP.NETLifeCycle.aspx

3/3

Вам также может понравиться