ASP.NET Page Life Cycle Dev Basics Series Jay Harris

Preview:

Citation preview

ASP.NET Page Life CycleDev Basics Series

Jay Harris

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

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

The AgendaAnatomy of the ASP.NET Page Life Cycle

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

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

The AgendaAnatomy of the ASP.NET Page Life Cycle

If IsPostBack:

Restores Properties from State

Page LoadStartInitializationLoad

Agenda

The AgendaAnatomy of the ASP.NET Page Life Cycle

Saves ViewState & Renders

RenderStartInitializationLoadRender

Agenda

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

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

The AgendaAnatomy of the ASP.NET Page Life Cycle

“SILVER!”(as in medals & bars)

Easy to RememberStartInitializationLoadValidationEventsRender

Agenda

The AgendaAnatomy of the ASP.NET Page Life Cycle

Wait. “SLIVER?!?”(no, not wood)

Easy to RememberStartLoadInitializationValidationEventsRender

Agenda

The AgendaAnatomy of the ASP.NET Page Life Cycle

Huh? “LIVER?!?”(eww. gross. and there’s no onions)

Easy to RememberStartLoadInitializationValidationEventsRender

Agenda

The AgendaAnatomy of the ASP.NET Page Life Cycle

“Hi-yo, Silver, away!”(The Lone Ranger)

Easy to RememberStartInitializationLoadValidationEventsRender

Agenda

Running the ShowHarnessing the ASP.NET Page Life Cycle*

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.

Debugging EventsTracing Page-Level

Features

Page-Level Tracing:

<%@ Page Trace=“true” %>

Running the ShowHarnessing the ASP.NET Page Life Cycle*

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*

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*

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.

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*

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*

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*

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*

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*

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*

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*

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?

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?

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*

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*

Displaying DataEffectively Binding Dynamic Data to the Page

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();

Displaying DataEffectively Binding Dynamic Data to the Page

DataBindingBegins DataBinding of a control

Binding EventsDataBind();Events

DataBinding

Data

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

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

Resources & Questions

Wrap-upTaking the Next Steps with the ASP.NET Page Life Cycle

ResourcesMSDN: http://tinyurl.com/AspNetPageLifeCycleBlog: http://www.cptloadtest.comEmail: jayharris@harrisdesigns.comTwitter: @jayharris

Questions?

Thank You

Wrap-upTaking the Next Steps with the ASP.NET Page Life Cycle

Jay Harris OnlineBlog: http://www.cptloadtest.comEmail: jayharris@harrisdesigns.comTwitter: @jayharris

FeedbackRate: http://www.speakerrate.com/jayharris

Recommended