Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

5/16/2014 ASP.

NET Page Life Cycle - CodeProject


http://www.codeproject.com/Articles/52857/ASP-NET-Page-Life-Cycle 1/4
10,610,782 members (36,909 online)


Sign in
home quick answers discussions features community
help
Search f or articles, questions, tips
Articles Web Development ASP.NET General

Article
Browse Code
Bugs / Suggestions
Stats
Revisions (2)
Alternatives
Comments (7)
View this article's
Workspace
Fork this Workspace
Connect using Git
Share
About Article
Explaining ASP.NET Page
Life Cycle
Type Article
Licence CPOL
First Posted 17 Jan 2010
Views 74,185
Downloads 937
Bookmarked 48 times
C#3.0 C# ASP.NET
Windows Beginner

Top News
The Secret Messages Inside
Chinese URLs
Get the Insider News free each
morning.
Related Videos
Related Articles
Understanding ASP.NET
Application and Page Life Cycle
- A Beginner's Tutorial
[Explained]Life Cycle of an
Rate this:
ASP.NET Page Life Cycle
By Indrajeet Sutar, 17 Jan 2010
Download source - 3.9 KB
Introduction
This is my first article on ASP.NET and I will try to explain the basics of ASP.NET page life cycle and an
easy understanding of its usage.
It is very important to understand ASP.NET page life cycle for many reasons, mainly for understanding
where we should place particular methods and when we should set page related properties. Additionally
if we are developing custom server controls, then clear understanding of page life cycle is very useful to
correct initialization of control, setting properties with view-state data, and controls code (Control
events are subject to ASP.NET page only).
Page life cycle depends on whether it is requested for the first time or it is after postback (page request
of itself) and finalize to the web server. When a web page is requested to the web server, it goes through
a series of sequence of steps/events (like initialization, instantiating controls, restoring and maintaining
state, running event handler code, and rendering) before it is returned back to the web browser.
When we use and manipulate page life cycle events correctly, then it becomes a handy and powerful tool
for developing web applications.
Background
IIS: It is the default web server with Microsoft .NET. Internet Information Server helps to deploy web
sites/web application. IIS web server receives requests for a web resource (file), it checks the extension of
the file (e.g. .aspx, .ascx, .ashx and .asmx) and then it determines which ISAPI extension should handle
this request and passes this request to proper ISAPI extension.
ASPNET_ISAPI.DLL: IIS loads this DLL and sends the page request to this DLL. This DLL loads the
HTTPRuntime for further processing.
ASPNET_WP.EXE: It contains an Application Pool. Each Application Pool can contain any number of
Applications. Application Pool is also called as AppDomain. When a web page is requested, IIS looks for
the application pool under which the current application is running and forwards the request to the
respective worker process.
Explanation
General Page Life Cycle Stages each and every time the browser sends the request, page instance is
created. HTTP runtime invokes ProcessRequest and starts page execution.
Table Showing Stage and Corresponding Events
3.56 (8 votes)
Sign up for our free weekly Web Developer Newsletter.
articles
5/16/2014 ASP.NET Page Life Cycle - CodeProject
http://www.codeproject.com/Articles/52857/ASP-NET-Page-Life-Cycle 2/4
[Explained]Life Cycle of an
ASP.NET Page
ASP.NET Page Life Cycle Events
ASP.NET Life Cycle Overview
ViewState and Server.Transfer
Best practices
The ASP.NET Page Lifecycle A
Basic Approach
ASP.NET Application and Page
Life Cycle
Callback WebControls
Client Callbacks in ASP.NET 2.0
Introducing ASP.NET Page
Modules
Extending ASP.NET role based
Security with Custom Security
Module (Permission Based,
Page Level Authorization)
Why not to pass endResponse
parameter as true in
Response.Redirect method
How to skip calling Page_Load
event
The Page Life Cycle of Client
[Browser]
Back to the basics: Exploration
of approaches to handle
ThreadAbortException with
Response.Redirect()
ASP.NET Web Form Model with
Partial Rendering and Events
Six common uses of the
Template Design Pattern:
Design Pattern series
Understanding ASP.NET MVC
(Model View Controller)
Architecture for Beginners
Developer Guidelines
Custom error pages for ALL file
types
Related Research
Fine-Tuning the Engines of SMB
Growth: 4 strategies for growing
your business
Learn Agile: Ten Tips for
Launching and Testing High
Quality Apps for the American
Market
Table Showing Stage and Corresponding Events
Stage Events/Method
Initialization of the page Page_Init
Loading of the View State LoadViewState
Processing of the Postback data LoadPostData
Loading of Page Page_Load
Notification of PostBack RaisePostDataChangedEvent
Handling of PostBack Event RaisePostBackEvent
Pre Rendering of Page Page_PreRender
Saving of view state SaveViewState
Rendering of Page Page_Render
Unloading of the Page Page_UnLoad
Setting Up Of the Page
ASP.NET determines that the page request by a user requires to be parsing and compiling or to render
cached copy of the page to be sent. Thus it comes very much before the beginning of the page life cycle.
After this, it is also checked that request is a normal request, postback, cross-page postback or callback.
The page constructor creates a tree of controls as soon as the HTTP runtime instantiates the page class
to perform the request.
Events
PreInit
This event is the beginning of the page life cycle. All page controls are initialized and the properties are
set according to the aspx source code.
Possible to change or set Master page, themes
Creates or re-creates dynamic controls
Reads or sets Profile property values
Init
First, the Init event for the Page object occurs, then Init event occurs for each control on the Page.
Viewstate information is not available at this stage.
Controls have been initialized
Theme skins applied if any
Initialize control properties
InitComplete
This event is used for processing tasks that require all initialization to be complete.
PreLoad
This event is used before performing any processing that should occur before Load. Use this event if you
need to perform processing on your page or control before the Load event. Before the Page instance
raises this event, it loads view state for itself and all controls, and then processes any postback data
included with the Request instance.
Load
Set properties in controls and establish database connections.
Control Events
5/16/2014 ASP.NET Page Life Cycle - CodeProject
http://www.codeproject.com/Articles/52857/ASP-NET-Page-Life-Cycle 3/4
Essential Keys to Mobile
Usability
Insider Secrets on API Security
From Experts at Securosis
[Webinar]
Indrajeet Sutar
Software Developer (Junior) Excel
Informatics, Pune
India
Am Indrajeet T. Sutar. I am a web developer. I am working on .net technology. I have completed
my Masters in Computers and Management (people call it as MCA, MBA etc.) Apart from
programming i do photography (not regularly though), traveling and reading books.
These are control specific events such as Button Click, DropDownIndexChanged, etc.
Load Complete
This event is used for performing those tasks which require load has been completed.
PreRender
In this event, Page ensures that all child controls are created. Page calls EnsureChildControls for
all controls, including itself. Every control whose datasource/databind property is set calls for its databind
method.
SaveStateComplete
This event occurs after viewstate is encoded and saved for the page and for all controls.
Render
Every ASP.NET control has render method and the page instance calls this method to output the
controls markup, after this event any changes to the page or controls are ignored.
Unload
Unload event is used to do cleanup tasks like closing the database connections, closing of the open files,
completing logging or other requested tasks. Unload events occurs for each control on page control tree
first and after that page.
History
18
th
January, 2010: Initial post
License
This article, along with any associated source code and files, is licensed under The Code Project Open
License (CPOL)
About the Author
Article Top
5/16/2014 ASP.NET Page Life Cycle - CodeProject
http://www.codeproject.com/Articles/52857/ASP-NET-Page-Life-Cycle 4/4
Permalink | Advertise | Privacy | Mobile
Web04 | 2.8.140512.1 | Last Updated 18 Jan 2010
Article Copyright 2010 by Indrajeet Sutar
Everything else Copyright CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid
Search this forum Go

Comments and Discussions
You must Sign In to use this message board.
Profile popups Spacing Relaxed Noise Medium Layout Normal Per page 25
Update
First Prev Next
Member 9319288
9-Jun-13 23:38
Member 4584908
4-Apr-11 20:31
davidreese
26-Jan-10 6:10
Shani Natav
26-Jan-10 2:38
rilov
18-Jan-10 16:35
Munim Abdul
19-Jan-10 23:13
Aric Green
17-Jan-10 23:51
Last Visit: 31-Dec-99 18:00 Last Update: 15-May-14 16:29 Refresh 1
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
InitEventHasBeenTreatedWrong
page life cycle in asp.net
My vote of 1
My vote of 2
ASP.net page life cycle..
Re: ASP.net page life cycle.. [modified]
Your Photo

You might also like