Dev Basics Series Jay Harris Overview What to expect out of this session Discuss ASPNET Page Life Cycle Proper use of Data Binding Events Involves only ASPNET Events No MVC No Silverlight ID: 133939
Download Presentation The PPT/PDF document "ASP.NET Page Life Cycle" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
ASP.NET Page Life Cycle
Dev Basics Series
Jay HarrisSlide2
Overview
What to expect out of this session
Discuss:
ASP.NET Page Life Cycle
Proper use of Data Binding EventsInvolves only ASP.NET EventsNo MVC. No Silverlight.No Controls or DataSource ControlsTips & Tricks. And Traps.
About the Talk
Life CycleData BindingTips & TricksPain Points
CoversSlide3
Overview
What to expect out of this session
Jay Harris
Software Consultant
.NET DeveloperAsk Questions AnytimePlease Give Feedback!http://www.speakerrate.com/jayharris/
About the Speaker
Life CycleData BindingTips & TricksPain Points
CoversSlide4
The Agenda
Anatomy of the ASP.NET Page Life CycleSlide5
The Agenda
Anatomy of the ASP.NET Page Life Cycle
System Assigns Properties:
Request
ResponseUICultureSystem determines if the request is new or postback
Page Start
StartAgendaSlide6
The Agenda
Anatomy of the ASP.NET Page Life Cycle
System Prepares Controls:
Available by
UniqueIDProperties set from code/CIF valuesApplies Theme & MasterPageHandled in PreInit
Page Initialization
StartInitializationAgendaSlide7
The Agenda
Anatomy of the ASP.NET Page Life Cycle
If
IsPostBack
:Restores Properties from StatePage Load
Start
InitializationLoadAgendaSlide8
The Agenda
Anatomy of the ASP.NET Page Life Cycle
Saves
ViewState
& RendersRender
Start
InitializationLoadRenderAgendaSlide9
The Agenda
Anatomy of the ASP.NET Page Life Cycle
If
IsPostBack
& Validators exist:Runs Validate() for All Validators…even the disabled ones
Control Validation
StartInitializationLoad ValidationRenderAgendaSlide10
The Agenda
Anatomy of the ASP.NET Page Life Cycle
If
IsPostBack
:Runs any Event Handlers as neededIncludes events such as:TextBox.TextChangedDropDownList.SelectedIndexChangedButton.Click
PostBack Events
StartInitializationLoad Validation EventsRender
AgendaSlide11
The Agenda
Anatomy of the ASP.NET Page Life Cycle
“SILVER!”
(as in medals & bars)
Easy to Remember
S
tartInitializationLoadValidationEventsRender
AgendaSlide12
The Agenda
Anatomy of the ASP.NET Page Life Cycle
Wait. “SLIVER?!?”
(no, not wood)
Easy to Remember
S
tartLoadInitializationValidationEventsRender
AgendaSlide13
The Agenda
Anatomy of the ASP.NET Page Life Cycle
Huh? “LIVER?!?”
(
eww. gross. and there’s no onions)Easy to Remember
S
tartLoadInitializationValidationEventsRender
AgendaSlide14
The Agenda
Anatomy of the ASP.NET Page Life Cycle
“Hi-
yo
, Silver, away!”(The Lone Ranger)Easy to Remember
S
tartInitializationLoadValidationEventsRender
AgendaSlide15
Running the Show
Harnessing the ASP.NET Page Life Cycle*Slide16
Running the Show
Harnessing the ASP.NET Page Life Cycle*
Subjected to the terms, limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, successors, and approval of the ASP.NET worker process.Slide17
Debugging Events
Tracing
Page-Level
Features
Page-Level Tracing:
<%@ Page Trace=“true” %>
Running the ShowHarnessing the ASP.NET Page Life Cycle*Slide18
Debugging Events
Tracing*
Page-Level*
Features
Page-Level Tracing:
<%@ Page Trace=“true” %>
*Not available after RenderSubjected to the terms, limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, successors, and approval of the ASP.NET worker process.Running the ShowHarnessing the ASP.NET Page Life Cycle*Slide19
Debugging Events
Tracing*
Page-Level*
App-Level
Features
Application-Level Tracing:
<configuration> <system.web>
<trace enabled=“true” />
</system.web>
</configuration>
Running the Show
Harnessing the ASP.NET Page Life Cycle*Slide20
Debugging Events
Tracing*
Page-Level*
App-Level*
Features
Application-Level Tracing:
<configuration> <system.web> <trace enabled=“true” /> </system.web></configuration>*Site-Wide Performance HitRunning the Show
Harnessing the ASP.NET Page Life Cycle*Subjected to the terms, limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, successors, and approval of the ASP.NET worker process.Slide21
Event Wiring
Tracing*
Wiring
Manual
Features
Using the Constructor:
public MyPage(){ this.Load += PageLoad;}
protected void PageLoad(…)Running the Show
Harnessing the ASP.NET Page Life Cycle*Slide22
Event Wiring
Tracing*
Wiring*
Manual*
Features
Using the Constructor:
public MyPage(){ this.Load += PageLoad;}
protected void PageLoad(…)*Wire Control events in Page Init
Subjected to the terms, limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, successors, and approval of the ASP.NET worker process.
Running the Show
Harnessing the ASP.NET Page Life Cycle*Slide23
Event Wiring, Auto
Tracing*
Wiring*
Manual*
Auto-Wire
Features
Auto-Wire via Page_EventName:protected void Page_Load(…){ //Do some stuff}
Running the ShowHarnessing the ASP.NET Page Life Cycle*Slide24
Event Wiring, Auto
Tracing*
Wiring*
Manual*
Auto-Wire*
Features
Auto-Wire via Page_EventName:protected void Page_Load(…){ //Do some stuff}*Page only. Not for controls.
*Performance Hit.Subjected to the terms, limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, successors, and approval of the ASP.NET worker process.
Running the Show
Harnessing the ASP.NET Page Life Cycle*Slide25
Event Execution
Tracing*
Wiring*
Execution
Tree
Features
Top-Down Control Tree ExecutionFirst load the Page
…then load the Container Control
…then load the Child Control
Running the Show
Harnessing the ASP.NET Page Life Cycle*Slide26
Event Execution
Tracing*
Wiring*
Execution*
Tree*
Features
Subjected to the terms, limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, successors, and approval of the ASP.NET worker process.Top-Down Control Tree ExecutionFirst load the Page
…then load the Container Control
…then load the Child Control
*Except: Initialization & Unload
First unload Controls, then the Page
Running the Show
Harnessing the ASP.NET Page Life Cycle*Slide27
Event Execution
Tracing*
Wiring*
Execution*
Tree*
Collection
FeaturesIndex-based Collection Executionpage.Controls[0].OnLoadpage.Controls[1].OnLoadpage.Controls[2].OnLoad
…page.Controls[n].OnLoadRunning the Show
Harnessing the ASP.NET Page Life Cycle*Slide28
Event Execution
Tracing*
Wiring*
Execution*
Tree*
Collection*
FeaturesSubjected to the terms, limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, successors, and approval of the ASP.NET worker process.Running the Show
Harnessing the ASP.NET Page Life Cycle*Index-based Collection Executionpage.Controls[0].
OnLoad
page.Controls
[1].
OnLoad
page.Controls
[2].
OnLoad
…
page.Controls
[n].
OnLoad
* When was it added to Controls?Slide29
Event Execution
Tracing*
Wiring*
Execution*
Tree*
Collection*
FeaturesSubjected to the terms, limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, successors, and approval of the ASP.NET worker process.Running the Show
Harnessing the ASP.NET Page Life Cycle*Index-based Collection Executionpage.Controls[0].
OnLoad
page.Controls
[1].
OnLoad
page.Controls
[2].
OnLoad
…
page.Controls
[n].
OnLoad
* When was it added to Controls?Slide30
Loading
ViewState
Tracing*
Wiring*
Execution
*
ViewStateFeaturesControl State is loaded twiceOnce immediately prior to Load
Once immediately following LoadRunning the Show
Harnessing the ASP.NET Page Life Cycle*Slide31
Loading
ViewState
Tracing*
Wiring*
Execution
*
ViewState*FeaturesSubjected to the terms, limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, successors, and approval of the ASP.NET worker process.Control State is loaded twice
Once immediately prior to Load
Once immediately following Load
*Not restored if modified prior
Running the Show
Harnessing the ASP.NET Page Life Cycle*Slide32
Displaying Data
Effectively Binding Dynamic Data to the PageSlide33
Displaying Data
Effectively Binding Dynamic Data to the Page
Control.DataBind
();
Only for the specific contoland its child controlsPage.DataBind();Binds all controls on the page
DataBind();
DataDataBind(); Slide34
Displaying Data
Effectively Binding Dynamic Data to the Page
DataBinding
Begins
DataBinding of a controlBinding Events
DataBind();
EventsDataBindingDataSlide35
Displaying Data
Effectively Binding Dynamic Data to the Page
RowCreated
/
ItemCreatedManipulating item markupCannot be dependent on control dataRow vs. Item Usage:RowCreated: GridViewItemCreated: DataGrid,ListView
, Repeater, and everything else.
Binding EventsDataBind();EventsDataBindingRwCreatedDataSlide36
Displaying Data
Effectively Binding Dynamic Data to the Page
RowDataBound
/
ItemDataBoundManipulating item dataData is available within controlsRow vs. Item Usage:RowCreated: GridViewItemCreated: DataGrid
, ListView, Repeater, and everything else.
Binding EventsDataBind();EventsDataBindingRwCreatedRwDBoundDataSlide37
Resources & Questions
Wrap-up
Taking the Next Steps with the ASP.NET Page Life Cycle
Resources
MSDN:
http://tinyurl.com/AspNetPageLifeCycleBlog: http://www.cptloadtest.com
Email: jayharris@harrisdesigns.comTwitter: @jayharrisQuestions?Slide38
Thank You
Wrap-up
Taking the Next Steps with the ASP.NET Page Life Cycle
Jay Harris
Online
Blog: http://www.cptloadtest.com
Email: jayharris@harrisdesigns.comTwitter: @jayharrisFeedbackRate: http://www.speakerrate.com/jayharris