Dev Basics: The ASP.NET Page Life Cycle

67 %
33 %
Information about Dev Basics: The ASP.NET Page Life Cycle
Technology

Published on June 30, 2009

Author: jayharris

Source: slideshare.net

Description

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.

ASP.NET Page Life Cycle Dev Basics Series Jay Harris

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

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

The Agenda Anatomy of the ASP.NET Page Life Cycle

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

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

Page Load Agenda Start If IsPostBack: Initialization Restores Properties from State Load The Agenda Anatomy of the ASP.NET Page Life Cycle

Render Agenda Start Saves ViewState & Renders Initialization Load Render The Agenda Anatomy of the ASP.NET Page Life Cycle

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

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

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

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

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

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

Running the Show Harnessing the ASP.NET Page Life Cycle*

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.

Debugging Events Features Page-Level Tracing: Tracing Page-Level <%@ Page Trace=“true” %> Running the Show Harnessing the ASP.NET Page Life Cycle*

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.

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*

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.

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*

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.

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*

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.

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*

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.

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*

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.

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.

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*

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.

Displaying Data Effectively Binding Dynamic Data to the Page

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

Binding Events Data DataBind(); DataBinding Events Begins DataBinding of a control DataBinding Displaying Data Effectively Binding Dynamic Data to the Page

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

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

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

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

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

ASP.NET Page Life Cycle - Jay Harris is Cpt. LoadTest

ASP.NET Page Life Cycle. Dev Basics Series. ... Discuss:ASP.NET Page Life CycleProper use of Data Binding Events. Involves only ASP.NET EventsNo MVC.
Read more

Dev Basics: ASP.NET Page Life Cycle, Part 1 [Events] - Jay ...

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 ...
Read more

Dev Basics: ASP.NET Page Life Cycle, Part 4 [Event Wireup ...

The first three parts of this series discuss the events that make up the ASP.NET Page Life Cycle, the order that these events execute on the page and on ...
Read more

ASP.NET Page Life Cycle Overview

ASP.NET Page Life Cycle ... The page request occurs before the page life cycle begins. When the page is requested ... (Overrides in Visual Basic), ...
Read more

ASP.NET basics: the page life cycle - TechRepublic

ASP.NET basics: the page life cycle. ... It is a basic ASP.NET 4.0 Web Form with TextBox and Literal controls. The code does not include all events, ...
Read more

Dev Basics: ASP.NET Page Life Cycle, Part 2 [WebControl ...

Dev Basics: ASP.NET Page Life Cycle, Part 2 [WebControl Execution Order] Jul 14, 2009 • Jay Harris
Read more

The ASP.NET Page Lifecycle – A Basic Approach - CodeProject

The ASP.NET Page Lifecycle – A Basic ... to Modern Dev/Test. ... because I was looking for a trick to remember Page Life Cycle. this article has ...
Read more

ASP.NET Page Life Cycle Events - CodeProject

A list of events in the ASP.NET page life cycle.; Author: Pavan Navule; Updated: 21 Aug 2012; Section: ASP.NET; Chapter: ... ASP.NET Dev. Stats.
Read more

Web Forms Page Processing

... Creating a Basic Web Forms Page. ... the ASP.NET page framework performs many Web application services for you. ... The Life Cycle of a Web Forms Page.
Read more