33
ASP.NET 2.0: ASP.NET 2.0: Advanced Server Controls Advanced Server Controls and Web Parts with and Web Parts with ASP.NET 2.0 ASP.NET 2.0 Sam Spencer Sam Spencer Program Manager Program Manager Web Platform and Tools Web Platform and Tools Microsoft Microsoft DEV414

ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Embed Size (px)

Citation preview

Page 1: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

ASP.NET 2.0: ASP.NET 2.0: Advanced Server Controls and Advanced Server Controls and Web Parts with ASP.NET 2.0 Web Parts with ASP.NET 2.0

Sam SpencerSam SpencerProgram ManagerProgram ManagerWeb Platform and ToolsWeb Platform and ToolsMicrosoftMicrosoft

DEV414

Page 2: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

AgendaAgenda

Control Framework overviewControl Framework overviewComposite control Composite control Script Object ModelScript Object ModelFocusFocusWeb resourcesWeb resourcesScript callbackScript callbackAsynchronous tasksAsynchronous tasksWeb Parts – Connection Web Parts – Connection Web Parts – Editing Web Parts – Editing Web Parts – Personalization Web Parts – Personalization Web Parts – Chrome Web Parts – Chrome

Page 3: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Control Framework OverviewControl Framework Overview

Rich framework to enable building “smart” Rich framework to enable building “smart” server controlsserver controls

Preserves existing knowledge and Preserves existing knowledge and compatibilitycompatibility

Same model as v1, but enables much moreSame model as v1, but enables much more

Simplifies development with more functional Simplifies development with more functional base classes targeting common scenariosbase classes targeting common scenarios

Incorporates learning and general Incorporates learning and general recommended patternsrecommended patterns

Provides new services and framework Provides new services and framework featuresfeatures

Page 4: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Recommended readingRecommended reading

Page 5: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Composite ControlsComposite Controls

Powerful way to create new controls by Powerful way to create new controls by combining the functionality of one or more combining the functionality of one or more existing controlsexisting controls

CompositeControl base class simplifies CompositeControl base class simplifies developmentdevelopment

New base class introduced in New base class introduced in Microsoft ASP.NET 2.0Microsoft ASP.NET 2.0

Incorporates recommended pattern Incorporates recommended pattern Implements INamingContainerImplements INamingContainer

Overrides Controls propertyOverrides Controls property

Overrides DataBind()Overrides DataBind()

Associated designer ensures child controls are Associated designer ensures child controls are created at design-time as wellcreated at design-time as well

Page 6: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Creating a Composite ControlCreating a Composite Control

Page 7: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Script OMScript OM

Provides new features such as: Provides new features such as: DefaultButtonDefaultButtonMaintain scroll position on PostbackMaintain scroll position on PostbackFocus, Setfocusonerror (for validator)Focus, Setfocusonerror (for validator)Web resources Web resources Out-of-band callbacksOut-of-band callbacks

Generate and render client-script Generate and render client-script Valid XHTML <script> tagsValid XHTML <script> tagsProvides API to register inline script or reference a *.js fileProvides API to register inline script or reference a *.js file

Available via Page.ClientScript objectAvailable via Page.ClientScript object

public void RegisterStartupScript( Type type, string key, public void RegisterStartupScript( Type type, string key, string script, bool addScriptTags);string script, bool addScriptTags);

public void RegisterClientScriptInclude( Type type, string key,public void RegisterClientScriptInclude( Type type, string key,string url);string url);

Page 8: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Define which control receives focus: Define which control receives focus: Page LevelPage Level

ControlControl

Controls can override to delegate focus Controls can override to delegate focus to a child control if they want explicit to a child control if they want explicit controlcontrol

FocusFocus

<form defaultfocus="foo1“<form defaultfocus="foo1“ .. .. >>

Control.Focus(..)Control.Focus(..)

public void Page.SetFocus(..);public void Page.SetFocus(..);

public bool BaseValidator.SetFocusonError;public bool BaseValidator.SetFocusonError;

Page 9: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Adding Focus support to the Adding Focus support to the controlcontrol

Page 10: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Web ResourcesWeb Resources

Simple deployment model of client filesSimple deployment model of client filesPackage scripts, images, style sheets, etc. as assembly Package scripts, images, style sheets, etc. as assembly resourcesresources

Instead of installing files into the “aspnet_client” folderInstead of installing files into the “aspnet_client” folder

ASP.NET does the work of serving up the ASP.NET does the work of serving up the contentcontent

Extracts data from the assembly resourceExtracts data from the assembly resource

Secure – all assembly resources do not automatically Secure – all assembly resources do not automatically become Web-accessiblebecome Web-accessible

Selects the right response caching for performanceSelects the right response caching for performance

[assembly: WebResource(“foo.image.bmp","image/gif")][assembly: WebResource(“foo.image.bmp","image/gif")]

img.ImageUrl = Page.ClientScript.GetWebResourceUrl(img.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), “foo.image.bmp");this.GetType(), “foo.image.bmp");

Page 11: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Embed Image into Custom Embed Image into Custom ControlControl

Page 12: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Script CallbacksScript Callbacks

Improves UI experienceImproves UI experiencePage is interactive while the server processes Page is interactive while the server processes requestrequest

No browser flashing or loss of scroll positionNo browser flashing or loss of scroll position

Does not add to the navigation historyDoes not add to the navigation history

Control developer writes some Control developer writes some additional codeadditional code

Modeled after post-back event handlingModeled after post-back event handling

Also implements a script callback functionAlso implements a script callback function

Page framework handles partial page Page framework handles partial page executionexecution

Page 13: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Click

InitInit

Load StateLoad State

Process Postback Process Postback DataData

LoadLoad

Script Event HandlerScript Event Handler

Script CallbackScript Callback

TriggerTrigger

Async RequestAsync Request

Return result ofReturn result ofCallbackCallback

CallbacksCallbacks ASP.NETASP.NET

RaiseCallbackEvent(…)RaiseCallbackEvent(…)

Async completesAsync completes

GetCallbackResult()GetCallbackResult()

Return resultReturn result

UnloadUnload

Manipulate DOMManipulate DOM

Page 14: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Adding callback support to the Adding callback support to the controlcontrol

Page 15: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Control StateControl State

The essential bits of information to allow controls to The essential bits of information to allow controls to ensure expected behaviorensure expected behavior

E.g., SelectedIndex, EditIndex, PageIndex on GridView; E.g., SelectedIndex, EditIndex, PageIndex on GridView; ReadOnly property on HtmlEditorReadOnly property on HtmlEditor

Separated out of view stateSeparated out of view statePage developer can turn off view state without losing Page developer can turn off view state without losing functionalityfunctionality

Control state cannot be turned offControl state cannot be turned off

Controls must opt-in to participate in this Controls must opt-in to participate in this mechanismmechanism

Should store only the essentials, so control state doesn’t Should store only the essentials, so control state doesn’t become another view statebecome another view state

Properties stored in control state should not be saved in Properties stored in control state should not be saved in view state as wellview state as well

Page 16: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Asynchronous TaskAsynchronous Task

Allow a container to register an Allow a container to register an asynchronous task to the page asynchronous task to the page

Container will be notified when task Container will be notified when task completed, time-out or endedcompleted, time-out or ended

Time Out is defined at the page Time Out is defined at the page directivedirective

Control developers can alter the Control developers can alter the rendering based on the async task rendering based on the async task resultresult

Page 17: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Adding Async Task(s) to a Adding Async Task(s) to a controlcontrol

Page 18: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Web Parts in 9 stepsWeb Parts in 9 steps

1.1. Enable AuthenticationEnable Authentication2.2. Configure Personalization DatabaseConfigure Personalization Database3.3. Add a Web Part Page ManagerAdd a Web Part Page Manager4.4. Add Web Part Page Menu (docs)Add Web Part Page Menu (docs)5.5. Add WebPart zonesAdd WebPart zones6.6. Add Controls, set titleAdd Controls, set title7.7. Add tool zones (optional)Add tool zones (optional)

Catalog ZoneCatalog ZoneEditor ZoneEditor ZoneConnections ZoneConnections Zone

8.8. Expose control properties (optional)Expose control properties (optional)9.9. Implement connections (optional)Implement connections (optional)

Page 19: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Web Parts: ConnectionWeb Parts: Connection

InterfaceInterfaceDefines the communication contract between two Defines the communication contract between two Web partsWeb parts

Connection typesConnection typesProvider Provider

Control that provides data and schema informationControl that provides data and schema information

Implements a provider connection point [ConnectionProvider]Implements a provider connection point [ConnectionProvider]Defines a call back that returns an instance of the interface Defines a call back that returns an instance of the interface

One provider connection point can connect to any number of One provider connection point can connect to any number of consumer connection points of the same typeconsumer connection points of the same type

Consumer Consumer Control that gets data Control that gets data

Implements a consumer connection point Implements a consumer connection point [ConnectionConsumer][ConnectionConsumer]

Defines a call back that gets an instance of the interface Defines a call back that gets an instance of the interface

One consumer connection point can connect to only one provider One consumer connection point can connect to only one provider connection points of the same typeconnection points of the same type

Page 20: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Web Parts: Connection (cont’d)Web Parts: Connection (cont’d)

1.1. Web Part Manager Web Part Manager request interface request interface to the providerto the provider

2.2. Web Part Manager Web Part Manager get an interface get an interface from a providerfrom a provider

3.3. Web Part manager Web Part manager give the interface give the interface to the consumerto the consumer

4.4. Consumer call Consumer call provider via provider via interface interface

ProviderProvider ConsumerConsumer

WebPartManagerWebPartManager

11

22 33

44

Page 21: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Web Parts: Connection (cont’d)Web Parts: Connection (cont’d)

Dynamic connections are done via the Dynamic connections are done via the browserbrowser

Static connections are defined by the Static connections are defined by the page developerpage developer

Page 22: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Implementing Connection Implementing Connection CapabilitiesCapabilities

Page 23: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Web Parts: EditingWeb Parts: Editing

Auto-generated user interfaceAuto-generated user interface[WebBrowsable][WebBrowsable]

[WebDisplayName][WebDisplayName]

[WebDescription][WebDescription]

Web Part can add a custom EditorPart to the Web Part can add a custom EditorPart to the EditorZoneEditorZone

Implement IWebEditable in the controlImplement IWebEditable in the controlReturn a collection of the Editor PartsReturn a collection of the Editor Parts

EditorPartCollection CreateEditorParts();EditorPartCollection CreateEditorParts();

Create an EditorPartCreate an EditorPartCreate a class that Inheritance from EditorPartCreate a class that Inheritance from EditorPart

Override:Override:Public abstract void SyncChanges();Public abstract void SyncChanges();

Protected internal abstract bool ApplyChanges();Protected internal abstract bool ApplyChanges();

Page 24: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Adding an Editing UI to the Adding an Editing UI to the ControlControl

Page 25: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Web Parts: PersonalizationWeb Parts: Personalization

Personalization scopePersonalization scopeSharedShared

Per-userPer-user

Personalizing dataPersonalizing dataAutomaticAutomatic

Add [WebPersonalization] decoration to propertiesAdd [WebPersonalization] decoration to properties

Must have a public get and set accessor , and take no Must have a public get and set accessor , and take no index parametersindex parameters

ManualManualImplement IPersonsonalizableImplement IPersonsonalizable

Provide fine-grained control over how control Provide fine-grained control over how control personalization data is get/setpersonalization data is get/set

Page 26: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Web Parts: Personalization (cont’d)Web Parts: Personalization (cont’d)

Receives notification about the Receives notification about the orphaned properties orphaned properties

Manager property persistence when Manager property persistence when upgrades to existing controlsupgrades to existing controls

Implement Implement IVersioningPersonsonalizableIVersioningPersonsonalizable

If a Web part does not implement If a Web part does not implement IVersioningPersonalizable, orphaned IVersioningPersonalizable, orphaned property values will be deleted property values will be deleted

Page 27: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

SummarySummary

Building control and advance features Building control and advance features could not be easiercould not be easier

Take Advantage of the new powerful Take Advantage of the new powerful framework features framework features

Building control and advance features Building control and advance features could not be easiercould not be easier

Take Advantage of the new powerful Take Advantage of the new powerful framework features framework features

Page 28: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

Get a 48% Discount on MSDN Get a 48% Discount on MSDN Universal Now!Universal Now! For a limited time purchase a 12 month For a limited time purchase a 12 month

MSDN Universal Subscription for MSDN Universal Subscription for $3565+GST (RRP).$3565+GST (RRP).

You will receive updates as they are You will receive updates as they are released for SQL Server, BizTalk Server, released for SQL Server, BizTalk Server, Visual Studio, Exchange Server and Visual Studio, Exchange Server and Windows Server. Windows Server.

You will also receive early access to beta You will also receive early access to beta products such as Windows Vista and products such as Windows Vista and Office 12.Office 12.

Get in now so that when Visual Studio Get in now so that when Visual Studio Team System ships you will be upgraded Team System ships you will be upgraded at no cost to one of the new top tier at no cost to one of the new top tier subscriptions:subscriptions:

Visual Studio 2005 Team Edition for Visual Studio 2005 Team Edition for Software DevelopersSoftware DevelopersVisual Studio 2005 Team Edition for Visual Studio 2005 Team Edition for Software ArchitectsSoftware ArchitectsVisual Studio 2005 Team Edition for Visual Studio 2005 Team Edition for Software TestersSoftware Testers

For more details and to find your local For more details and to find your local reseller visit: reseller visit: www.microsoft.co.nz/buyMSDNwww.microsoft.co.nz/buyMSDN

Page 29: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414
Page 30: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

We invite you to participate in ourWe invite you to participate in our online evaluationonline evaluation on CommNet,on CommNet,

accessible Friday onlyaccessible Friday only

If you choose to complete the evaluation online, If you choose to complete the evaluation online, there isthere is no need to complete the paper evaluationno need to complete the paper evaluation

Page 31: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414
Page 32: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Page 33: ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Sam Spencer Program Manager Web Platform and Tools Microsoft DEV414