asp.net page life cycle dev basics series jay harris
TRANSCRIPT
![Page 1: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/1.jpg)
ASP.NET Page Life CycleDev Basics Series
Jay Harris
![Page 2: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/2.jpg)
OverviewWhat to expect out of this session
Discuss:
ASP.NET Page Life CycleProper use of Data Binding Events
Involves only ASP.NET Events
No MVC. No Silverlight.No Controls or DataSource Controls
Tips & Tricks. And Traps.
About the TalkLife CycleData BindingTips & TricksPain Points
Covers
![Page 3: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/3.jpg)
OverviewWhat to expect out of this session
Jay HarrisSoftware Consultant.NET Developer
Ask Questions Anytime
Please Give Feedback!http://www.speakerrate.com/jayharris/
About the SpeakerLife CycleData BindingTips & TricksPain Points
Covers
![Page 4: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/4.jpg)
The AgendaAnatomy of the ASP.NET Page Life Cycle
![Page 5: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/5.jpg)
The AgendaAnatomy of the ASP.NET Page Life Cycle
System Assigns Properties:
RequestResponseUICulture
System determines if the request is new or postback
Page StartStart
Agenda
![Page 6: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/6.jpg)
The AgendaAnatomy of the ASP.NET Page Life Cycle
System Prepares Controls:
Available by UniqueIDProperties set from code/CIF values
Applies Theme & MasterPage
Handled in PreInit
Page InitializationStartInitialization
Agenda
![Page 7: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/7.jpg)
The AgendaAnatomy of the ASP.NET Page Life Cycle
If IsPostBack:
Restores Properties from State
Page LoadStartInitializationLoad
Agenda
![Page 8: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/8.jpg)
The AgendaAnatomy of the ASP.NET Page Life Cycle
Saves ViewState & Renders
RenderStartInitializationLoadRender
Agenda
![Page 9: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/9.jpg)
The AgendaAnatomy of the ASP.NET Page Life Cycle
If IsPostBack & Validators exist:
Runs Validate() for All Validators…even the disabled ones
Control ValidationStartInitializationLoad ValidationRender
Agenda
![Page 10: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/10.jpg)
The AgendaAnatomy of the ASP.NET Page Life Cycle
If IsPostBack:
Runs any Event Handlers as needed
Includes events such as:
TextBox.TextChangedDropDownList.SelectedIndexChangedButton.Click
PostBack EventsStartInitializationLoad Validation EventsRender
Agenda
![Page 11: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/11.jpg)
The AgendaAnatomy of the ASP.NET Page Life Cycle
“SILVER!”(as in medals & bars)
Easy to RememberStartInitializationLoadValidationEventsRender
Agenda
![Page 12: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/12.jpg)
The AgendaAnatomy of the ASP.NET Page Life Cycle
Wait. “SLIVER?!?”(no, not wood)
Easy to RememberStartLoadInitializationValidationEventsRender
Agenda
![Page 13: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/13.jpg)
The AgendaAnatomy of the ASP.NET Page Life Cycle
Huh? “LIVER?!?”(eww. gross. and there’s no onions)
Easy to RememberStartLoadInitializationValidationEventsRender
Agenda
![Page 14: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/14.jpg)
The AgendaAnatomy of the ASP.NET Page Life Cycle
“Hi-yo, Silver, away!”(The Lone Ranger)
Easy to RememberStartInitializationLoadValidationEventsRender
Agenda
![Page 15: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/15.jpg)
Running the ShowHarnessing the ASP.NET Page Life Cycle*
![Page 16: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/16.jpg)
Running the ShowHarnessing 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.
![Page 17: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/17.jpg)
Debugging EventsTracing Page-Level
Features
Page-Level Tracing:
<%@ Page Trace=“true” %>
Running the ShowHarnessing the ASP.NET Page Life Cycle*
![Page 18: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/18.jpg)
Debugging EventsTracing* Page-Level*
Features
Page-Level Tracing:
<%@ Page Trace=“true” %>
*Not available after Render
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 ShowHarnessing the ASP.NET Page Life Cycle*
![Page 19: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/19.jpg)
Debugging EventsTracing* Page-Level* App-Level
Features
Application-Level Tracing:
<configuration> <system.web> <trace enabled=“true” /> </system.web></configuration>
Running the ShowHarnessing the ASP.NET Page Life Cycle*
![Page 20: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/20.jpg)
Debugging EventsTracing* Page-Level* App-Level*
Features
Application-Level Tracing:
<configuration> <system.web> <trace enabled=“true” /> </system.web></configuration>
*Site-Wide Performance Hit
Running the ShowHarnessing 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.
![Page 21: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/21.jpg)
Event WiringTracing*Wiring Manual
Features
Using the Constructor:
public MyPage(){ this.Load += PageLoad;}protected void PageLoad(…)
Running the ShowHarnessing the ASP.NET Page Life Cycle*
![Page 22: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/22.jpg)
Event WiringTracing*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 ShowHarnessing the ASP.NET Page Life Cycle*
![Page 23: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/23.jpg)
Event Wiring, AutoTracing*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*
![Page 24: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/24.jpg)
Event Wiring, AutoTracing*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 ShowHarnessing the ASP.NET Page Life Cycle*
![Page 25: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/25.jpg)
Event ExecutionTracing*Wiring*Execution
Tree
Features
Top-Down Control Tree Execution
First load the Page…then load the Container Control…then load the Child Control
Running the ShowHarnessing the ASP.NET Page Life Cycle*
![Page 26: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/26.jpg)
Event ExecutionTracing*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 Execution
First load the Page…then load the Container Control…then load the Child Control
*Except: Initialization & Unload
First unload Controls, then the Page
Running the ShowHarnessing the ASP.NET Page Life Cycle*
![Page 27: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/27.jpg)
Event ExecutionTracing*Wiring*Execution*
Tree*Collection
Features
Index-based Collection Execution
page.Controls[0].OnLoadpage.Controls[1].OnLoadpage.Controls[2].OnLoad…page.Controls[n].OnLoad
Running the ShowHarnessing the ASP.NET Page Life Cycle*
![Page 28: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/28.jpg)
Event ExecutionTracing*Wiring*Execution*
Tree*Collection*
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.
Running the ShowHarnessing the ASP.NET Page Life Cycle*
Index-based Collection Execution
page.Controls[0].OnLoadpage.Controls[1].OnLoadpage.Controls[2].OnLoad…page.Controls[n].OnLoad
* When was it added to Controls?
![Page 29: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/29.jpg)
Event ExecutionTracing*Wiring*Execution*
Tree*Collection*
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.
Running the ShowHarnessing the ASP.NET Page Life Cycle*
Index-based Collection Execution
page.Controls[0].OnLoadpage.Controls[1].OnLoadpage.Controls[2].OnLoad…page.Controls[n].OnLoad
* When was it added to Controls?
![Page 30: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/30.jpg)
Loading ViewStateTracing*Wiring*Execution*ViewState
Features
Control State is loaded twice
Once immediately prior to LoadOnce immediately following Load
Running the ShowHarnessing the ASP.NET Page Life Cycle*
![Page 31: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/31.jpg)
Loading ViewStateTracing*Wiring*Execution*ViewState*
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.
Control State is loaded twice
Once immediately prior to LoadOnce immediately following Load
*Not restored if modified prior
Running the ShowHarnessing the ASP.NET Page Life Cycle*
![Page 32: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/32.jpg)
Displaying DataEffectively Binding Dynamic Data to the Page
![Page 33: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/33.jpg)
Displaying DataEffectively Binding Dynamic Data to the Page
Control.DataBind();
Only for the specific contoland its child controls
Page.DataBind();
Binds all controls on the page
DataBind(); DataDataBind();
![Page 34: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/34.jpg)
Displaying DataEffectively Binding Dynamic Data to the Page
DataBindingBegins DataBinding of a control
Binding EventsDataBind();Events
DataBinding
Data
![Page 35: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/35.jpg)
Displaying DataEffectively Binding Dynamic Data to the Page
RowCreated / ItemCreated
Manipulating item markupCannot be dependent on control data
Row vs. Item Usage:
RowCreated: GridViewItemCreated: DataGrid,ListView, Repeater, and everything else.
Binding EventsDataBind();Events
DataBindingRwCreated
Data
![Page 36: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/36.jpg)
Displaying DataEffectively Binding Dynamic Data to the Page
RowDataBound / ItemDataBound
Manipulating item dataData is available within controls
Row vs. Item Usage:
RowCreated: GridViewItemCreated: DataGrid, ListView, Repeater, and everything else.
Binding EventsDataBind();Events
DataBindingRwCreatedRwDBound
Data
![Page 37: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/37.jpg)
Resources & Questions
Wrap-upTaking the Next Steps with the ASP.NET Page Life Cycle
ResourcesMSDN: http://tinyurl.com/AspNetPageLifeCycleBlog: http://www.cptloadtest.comEmail: [email protected]: @jayharris
Questions?
![Page 38: ASP.NET Page Life Cycle Dev Basics Series Jay Harris](https://reader034.vdocuments.us/reader034/viewer/2022042714/551aa246550346761a8b608a/html5/thumbnails/38.jpg)
Thank You
Wrap-upTaking the Next Steps with the ASP.NET Page Life Cycle
Jay Harris OnlineBlog: http://www.cptloadtest.comEmail: [email protected]: @jayharris
FeedbackRate: http://www.speakerrate.com/jayharris