asp net page life cycle

24
Presented By : Abhishek Sur http://www.abhisheksur.com/

Upload: siddharth-tyagi

Post on 06-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 1/24

Presented By : Abhishek Surhttp://www.abhisheksur.com/

Page 2: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 2/24

Table of Contenty Introduction

y  Application Life Cycley IIS Request Process

y  Application Pool

y  Worker Process

y HTTP Handler/Module

y  ASP.NET Page Life Cycle

y Page Life Cycle Stepsy Page Life Cycle Events

y Life Cycle for Master Page and User Control

y QA 

Page 3: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 3/24

Introductiony When Clients request for an aspx page from browser

and lot of stuffs happens in background to produce the

output or sending response to client. This evolves ASP.NET Page Lifecycle.

y ASP.NET Page Life Cycle is very much important toknow for each and every developer to developed an

 ASP.NET Web Application.y All events, data processing, dynamic control creation,

 view state, postback, rendering etc. are depends withPage Life Cycle.

Page 4: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 4/24

Application Life Cycle1. Client Request For Information2. Request comes to Server3. Server Process the request

4. Send the response back to Client

Page 5: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 5/24

Application Life Cycle - Contd.y Key terms to remember

y HTTP.SYS

y  WAS

y  Application Pool

y  Worker Process

http://blogs.thesitedoctor.co.uk/tim/2006/06/30/Complete+Lifecycle+Of+A

n+ASPNet+Page+And+Controls.aspx

Page 6: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 6/24

Application Life Cycle Contd.y Key Terms To Remember

y Http Module

y

Http Handlery Http Pipeline

Page 7: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 7/24

End Of Application Life Cycle Start Page Life Cycle

y Request Passes Through HTTP Pipe Liney This Start Page Life Cycle

Page 8: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 8/24

ASP.NET Page Life Cycle Beginsy Start

y Initialization

y Loady Validation

y Events

y Render

S I L

 V ER 

Page 9: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 9/24

Page Life Cycle - Starty Client Request For Resource

y Request Comes To Server (IIS)

y IIS Process the Initial Processingy Request Passed through HTTP- Pipe Line

y ASP.NET Page Life Cycle Starts

Page 10: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 10/24

Page Life Cycle - Initializationy Set Postback properties

y Unique ID for Each Control in the Page

y Themes needs to be initializedy D ynamic control need to be created

Page 11: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 11/24

Page Life Cycle - Loady If the Request is the post back request then it loads

data from View States and Control State

Page 12: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 12/24

Page Life Cycle - Validationy Validate the pages Control

y Updates the IsValid property 

Page 13: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 13/24

Page Life Cycle - Eventsy This will only fired if the request is an postback event.

y Like, if the post back is happened for an Button Click.

Button Click event will fired.

Page 14: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 14/24

Page Life Cycle - Rendery Before Rendering All View State data has been set.

y Render() method for all control has been called and

 write the out put on output stream.

Page 15: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 15/24

Page Life Cycle - Events

http://msdn.microsoft.com/en-us/library/ms178472.aspx

Page 16: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 16/24

ASP.NET Page Life Cycle Eventsy PreInit

y Init

y PreLoady Load

y Control Events

y PreRender

y SaveViewState

y Render

y Unload

Page 17: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 17/24

Page Life Cycle Eventsy PreInit()

y This is the first event which raised in asp.net page lifecycle

y

Check for Request is for Post Back or not.y  All dynamic control need to be created

y Theme Change, Master Page Set at runtime

y Init()y Raised after all controls have been initialized

y Build up a tree of controls from the ASPX file

y Turn on view state monitoring any changes in control will betracked by View State for future.

Page 18: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 18/24

Page Life Cycle - Eventsy PreLoad()

y Load view state data for page and controls

y

Load Postback data if neededy  We can process any kind operation that need to perform

before page load

y Load()y OnLoad methods control called for each and every control

y  We can create the connection initialization for any kind of external source like database connection

y  We can also set the control properties

Page 19: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 19/24

Page Life Cycle - Events

y Control Eventsy If this is an postback request , Corresponding events will triggered.

Like, if the post back is happing for button click, then Button_ClickEvent will fired.

y PreRendery Each control of the page has a PreRender event which is being

invoked.

y EnsureChildControls is also being called during this events

y DataBind method for all control has also been called

y If we want to change any thing to any control this is the last event where we can do because after the pageRender starts

Page 20: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 20/24

Page Life Cycle - Eventsy SaveViewState

y  ViewState Monitoring is turned off as here all the ViewStateData need to be saved.

y  View State data saved in hidden filed called _V IEWSTATE

y Rendery Pages calls the Render method for each and every control.

y Text writer that writes the output to the as output stream

y Output steam set to the page's Response property.

Page 21: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 21/24

Page Life Cycle - Eventsy Unload

y This is the last event of asp.net page life cycle

y

This ensure the Request and Response has been set to null.y This is called only after the content of the page fully rendered

and response sent to client

Page 22: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 22/24

Page Life Cycle - Master Page and User Controlsy MasterPage gets initialized from the Page class in the init phaze

of page. The content of Masterpage gets loaded side by side asthe page gets loaded.

y User control will be initialized and added to the page and beforepage gets initialized

y  After page Onload, MasterPage_OnLoad gets called andUserControl_Onload gets called sequentially.

y Followed by each of Page events, masterPage events gets calledand next Usercontrol events are called.

y During the unload phaze, Usercontrol gets unloaded first andthen masterpage and Page in sequence.y For further reference refer to :

http://blogs.thesitedoctor.co.uk/tim/2006/06/30/Complete+Lifecycle+Of+An+ASPNet+Page+And+Controls.aspx

Page 23: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 23/24

Q/A

Page 24: ASP Net Page Life Cycle

8/3/2019 ASP Net Page Life Cycle

http://slidepdf.com/reader/full/asp-net-page-life-cycle 24/24

Thank you