ASP.NET Page Life Cycle
                Dev Basics Series
                       Jay Harris
About the Talk                         Covers
                                       Life Cycle
Discuss:                  ...
About the Speaker                         Covers
                                          Life Cycle
Jay Harris          ...
The Agenda
Anatomy of the ASP.NET Page Life Cycle
Page Start                               Agenda
                                         Start
System Assigns Properties:
...
Page Initialization                      Agenda
                                         Start
System Prepares Controls:  ...
Page Load                                Agenda
                                         Start
If IsPostBack:             ...
Render                                   Agenda
                                         Start
Saves ViewState & Renders  ...
Control Validation                       Agenda
                                         Start
If IsPostBack & Validators ...
PostBack Events                          Agenda
                                         Start
If IsPostBack:             ...
Easy to Remember                         Agenda
                                         Start
                           ...
Easy to Remember                         Agenda
                                         Start
                           ...
Easy to Remember                           Agenda
                                           Start
                       ...
Easy to Remember                         Agenda
                                         Start
                           ...
Running the Show
Harnessing the ASP.NET Page Life Cycle*
Subjected to the terms,


Running the Show
                                          limitations, availability, whims,
   ...
Debugging Events                          Features
Page-Level Tracing:                       Tracing
                     ...
Debugging Events                          Features
Page-Level Tracing:                       Tracing*
                    ...
Debugging Events                          Features
Application-Level Tracing:                Tracing*
                    ...
Debugging Events                          Features
Application-Level Tracing:                Tracing*
                    ...
Event Wiring                              Features
Using the Constructor:                    Tracing*
                    ...
Event Wiring                              Features
Using the Constructor:                    Tracing*
                    ...
Event Wiring, Auto                        Features
Auto-Wire via Page_EventName:             Tracing*
                    ...
Event Wiring, Auto                        Features
Auto-Wire via Page_EventName:             Tracing*
                    ...
Event Execution                           Features
Top-Down Control Tree Execution           Tracing*
                    ...
Event Execution                           Features
Top-Down Control Tree Execution           Tracing*
                    ...
Event Execution                           Features
Index-based Collection Execution          Tracing*
                    ...
Event Execution                           Features
Index-based Collection Execution          Tracing*
                    ...
Event Execution                           Features
Index-based Collection Execution          Tracing*
                    ...
Loading ViewState                         Features
Control State is loaded twice             Tracing*
                    ...
Loading ViewState                         Features
Control State is loaded twice             Tracing*
                    ...
Displaying Data
Effectively Binding Dynamic Data to the Page
DataBind();                                    Data
                                               DataBind();
Control.Dat...
Binding Events                                 Data
                                               DataBind();
DataBinding...
Binding Events                                 Data
                                               DataBind();
RowCreated ...
Binding Events                                 Data
                                               DataBind();
RowDataBoun...
Resources & Questions
Resources
 MSDN:         http://tinyurl.com/AspNetPageLifeCycle
 Blog:         http://www.cptloadtes...
Thank You
Jay Harris Online
 Blog:         http://www.cptloadtest.com
 Twitter:      @jayharris

Feedback
 Rate:         h...
Upcoming SlideShare
Loading in …5
×

Dev Basics: The ASP.NET Page Life Cycle

7,980 views

Published on

When a request occurs for an ASP.Net page, the response is processed through a series of events before being sent to the client browser. These events, known as the Page Life Cycle, are a complicated headache when used improperly, manifesting as odd exceptions, incorrect data, performance issues, and general confusion. It seems simple when reading yet-another-book-on-ASP.NET, but never when applied in the real world. In this session, we decompose this mess, and turn the Life Cycle into an effective and productive tool. No ASP.NET MVC, no Dynamic Data, no MoroRail, no technologies of tomorrow, just the basics of ASP.NET, using the tools we have available in the office, today.

Published in: Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,980
On SlideShare
0
From Embeds
0
Number of Embeds
30
Actions
Shares
0
Downloads
0
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Dev Basics: The ASP.NET Page Life Cycle

  1. 1. ASP.NET Page Life Cycle Dev Basics Series Jay Harris
  2. 2. About the Talk Covers Life Cycle Discuss: Data Binding ASP.NET Page Life Cycle Tips & Tricks Proper use of Data Binding Events Pain Points Involves only ASP.NET Events No MVC. No Silverlight. No Controls or DataSource Controls Tips & Tricks. And Traps. Overview What to expect out of this session
  3. 3. About the Speaker Covers Life Cycle Jay Harris Data Binding Software Consultant Tips & Tricks .NET Developer Pain Points Ask Questions Anytime Please Give Feedback! http://www.speakerrate.com/jayharris/ Overview What to expect out of this session
  4. 4. The Agenda Anatomy of the ASP.NET Page Life Cycle
  5. 5. Page Start Agenda Start System Assigns Properties: Request Response UICulture System determines if the request is new or postback The Agenda Anatomy of the ASP.NET Page Life Cycle
  6. 6. Page Initialization Agenda Start System Prepares Controls: Initialization Available by UniqueID Properties set from code/CIF values Applies Theme & MasterPage Handled in PreInit The Agenda Anatomy of the ASP.NET Page Life Cycle
  7. 7. Page Load Agenda Start If IsPostBack: Initialization Restores Properties from State Load The Agenda Anatomy of the ASP.NET Page Life Cycle
  8. 8. Render Agenda Start Saves ViewState & Renders Initialization Load Render The Agenda Anatomy of the ASP.NET Page Life Cycle
  9. 9. Control Validation Agenda Start If IsPostBack & Validators exist: Initialization Runs Validate() for All Validators Load …even the disabled ones Validation Render The Agenda Anatomy of the ASP.NET Page Life Cycle
  10. 10. PostBack Events Agenda Start If IsPostBack: Initialization Runs any Event Handlers as needed Load Validation Includes events such as: Events Render TextBox.TextChanged DropDownList.SelectedIndexChanged Button.Click The Agenda Anatomy of the ASP.NET Page Life Cycle
  11. 11. Easy to Remember Agenda Start Initialization Load Validation “SILVER!” Events (as in medals & bars) Render The Agenda Anatomy of the ASP.NET Page Life Cycle
  12. 12. Easy to Remember Agenda Start Load Initialization Validation Wait. “SLIVER?!?” Events (no, not wood) Render The Agenda Anatomy of the ASP.NET Page Life Cycle
  13. 13. Easy to Remember Agenda Start Load Initialization Validation Huh? “LIVER?!?” Events (eww. gross. and there’s no onions) Render The Agenda Anatomy of the ASP.NET Page Life Cycle
  14. 14. Easy to Remember Agenda Start Initialization Load Validation “Hi-yo, Silver, away!” Events (The Lone Ranger) Render The Agenda Anatomy of the ASP.NET Page Life Cycle
  15. 15. Running the Show Harnessing the ASP.NET Page Life Cycle*
  16. 16. Subjected to the terms, Running the Show limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, Harnessing the ASP.NET Page Life Cycle* successors, and approval of the ASP.NET worker process.
  17. 17. Debugging Events Features Page-Level Tracing: Tracing Page-Level <%@ Page Trace=“true” %> Running the Show Harnessing the ASP.NET Page Life Cycle*
  18. 18. Debugging Events Features Page-Level Tracing: Tracing* Page-Level* <%@ Page Trace=“true” %> *Not available after Render Subjected to the terms, Running the Show limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, Harnessing the ASP.NET Page Life Cycle* successors, and approval of the ASP.NET worker process.
  19. 19. Debugging Events Features Application-Level Tracing: Tracing* Page-Level* App-Level <configuration> <system.web> <trace enabled=“true” /> </system.web> </configuration> Running the Show Harnessing the ASP.NET Page Life Cycle*
  20. 20. Debugging Events Features Application-Level Tracing: Tracing* Page-Level* App-Level* <configuration> <system.web> <trace enabled=“true” /> </system.web> </configuration> *Site-Wide Performance Hit Subjected to the terms, Running the Show limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, Harnessing the ASP.NET Page Life Cycle* successors, and approval of the ASP.NET worker process.
  21. 21. Event Wiring Features Using the Constructor: Tracing* Wiring Manual public MyPage() { this.Load += PageLoad; } protected void PageLoad(…) Running the Show Harnessing the ASP.NET Page Life Cycle*
  22. 22. Event Wiring Features Using the Constructor: Tracing* Wiring* Manual* public MyPage() { this.Load += PageLoad; } protected void PageLoad(…) *Wire Control events in Page Init Subjected to the terms, Running the Show limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, Harnessing the ASP.NET Page Life Cycle* successors, and approval of the ASP.NET worker process.
  23. 23. Event Wiring, Auto Features Auto-Wire via Page_EventName: Tracing* Wiring* Manual* protected void Page_Load(…) Auto-Wire { //Do some stuff } Running the Show Harnessing the ASP.NET Page Life Cycle*
  24. 24. Event Wiring, Auto Features Auto-Wire via Page_EventName: Tracing* Wiring* Manual* protected void Page_Load(…) Auto-Wire* { //Do some stuff } *Page only. Not for controls. *Performance Hit. Subjected to the terms, Running the Show limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, Harnessing the ASP.NET Page Life Cycle* successors, and approval of the ASP.NET worker process.
  25. 25. Event Execution Features Top-Down Control Tree Execution Tracing* Wiring* Execution First load the Page Tree …then load the Container Control …then load the Child Control Running the Show Harnessing the ASP.NET Page Life Cycle*
  26. 26. Event Execution Features Top-Down Control Tree Execution Tracing* Wiring* Execution* First load the Page Tree* …then load the Container Control …then load the Child Control *Except: Initialization & Unload First unload Controls, then the Page Subjected to the terms, Running the Show limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, Harnessing the ASP.NET Page Life Cycle* successors, and approval of the ASP.NET worker process.
  27. 27. Event Execution Features Index-based Collection Execution Tracing* Wiring* Execution* page.Controls[0].OnLoad Tree* page.Controls[1].OnLoad Collection page.Controls[2].OnLoad … page.Controls[n].OnLoad Running the Show Harnessing the ASP.NET Page Life Cycle*
  28. 28. Event Execution Features Index-based Collection Execution Tracing* Wiring* Execution* page.Controls[0].OnLoad Tree* page.Controls[1].OnLoad Collection* page.Controls[2].OnLoad … page.Controls[n].OnLoad * When was it added to Controls? Subjected to the terms, Running the Show limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, Harnessing the ASP.NET Page Life Cycle* successors, and approval of the ASP.NET worker process.
  29. 29. Event Execution Features Index-based Collection Execution Tracing* Wiring* Execution* page.Controls[0].OnLoad Tree* page.Controls[1].OnLoad Collection* page.Controls[2].OnLoad … page.Controls[n].OnLoad * When was it added to Controls? Subjected to the terms, Running the Show limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, Harnessing the ASP.NET Page Life Cycle* successors, and approval of the ASP.NET worker process.
  30. 30. Loading ViewState Features Control State is loaded twice Tracing* Wiring* Execution* Once immediately prior to Load ViewState Once immediately following Load Running the Show Harnessing the ASP.NET Page Life Cycle*
  31. 31. Loading ViewState Features Control State is loaded twice Tracing* Wiring* Execution* Once immediately prior to Load ViewState* Once immediately following Load *Not restored if modified prior Subjected to the terms, Running the Show limitations, availability, whims, will, desires, rules, patterns, provisions, agreements, covenants, conditions, assigns, Harnessing the ASP.NET Page Life Cycle* successors, and approval of the ASP.NET worker process.
  32. 32. Displaying Data Effectively Binding Dynamic Data to the Page
  33. 33. DataBind(); Data DataBind(); Control.DataBind(); Only for the specific contol and its child controls Page.DataBind(); Binds all controls on the page Displaying Data Effectively Binding Dynamic Data to the Page
  34. 34. Binding Events Data DataBind(); DataBinding Events Begins DataBinding of a control DataBinding Displaying Data Effectively Binding Dynamic Data to the Page
  35. 35. Binding Events Data DataBind(); RowCreated / ItemCreated Events Manipulating item markup DataBinding Cannot be dependent on control data RwCreated Row vs. Item Usage: RowCreated: GridView ItemCreated: DataGrid,ListView, Repeater, and everything else. Displaying Data Effectively Binding Dynamic Data to the Page
  36. 36. Binding Events Data DataBind(); RowDataBound / ItemDataBound Events Manipulating item data DataBinding Data is available within controls RwCreated RwDBound Row vs. Item Usage: RowCreated: GridView ItemCreated: DataGrid, ListView, Repeater, and everything else. Displaying Data Effectively Binding Dynamic Data to the Page
  37. 37. Resources & Questions Resources MSDN: http://tinyurl.com/AspNetPageLifeCycle Blog: http://www.cptloadtest.com Twitter: @jayharris Questions? Wrap-up Taking the Next Steps with the ASP.NET Page Life Cycle
  38. 38. Thank You Jay Harris Online Blog: http://www.cptloadtest.com Twitter: @jayharris Feedback Rate: http://www.speakerrate.com/jayharris Wrap-up Taking the Next Steps with the ASP.NET Page Life Cycle

×