Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations

Presentation on theme: "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."— Presentation transcript:

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

2 Agenda Control Framework overview Composite control Script Object Model Focus Web resources Script callback Asynchronous tasks Web Parts – Connection Web Parts – Editing Web Parts – Personalization Web Parts – Chrome

3 Control Framework Overview Rich framework to enable building “smart” server controls Preserves existing knowledge and compatibility Same model as v1, but enables much more Simplifies development with more functional base classes targeting common scenarios Incorporates learning and general recommended patterns Provides new services and framework features

4 Recommended reading

5 Composite Controls Powerful way to create new controls by combining the functionality of one or more existing controls CompositeControl base class simplifies development New base class introduced in Microsoft ASP.NET 2.0 Incorporates recommended pattern Implements INamingContainer Overrides Controls property Overrides DataBind() Associated designer ensures child controls are created at design-time as well

6 Creating a Composite Control

7 Script OM Provides new features such as: DefaultButton Maintain scroll position on Postback Focus, Setfocusonerror (for validator) Web resources Out-of-band callbacks Generate and render client-script Valid XHTML tags Provides API to register inline script or reference a *.js file Available via Page.ClientScript object public void RegisterStartupScript( Type type, string key, string script, bool addScriptTags); public void RegisterClientScriptInclude( Type type, string key, string url);

8 Define which control receives focus: Page Level Control Controls can override to delegate focus to a child control if they want explicit control Focus Control.Focus(..) public void Page.SetFocus(..); public bool BaseValidator.SetFocusonError;

9 Adding Focus support to the control

10 Web Resources Simple deployment model of client files Package scripts, images, style sheets, etc. as assembly resources Instead of installing files into the “aspnet_client” folder ASP.NET does the work of serving up the content Extracts data from the assembly resource Secure – all assembly resources do not automatically become Web-accessible Selects the right response caching for performance [assembly: WebResource(“foo.image.bmp","image/gif")] img.ImageUrl = Page.ClientScript.GetWebResourceUrl( this.GetType(), “foo.image.bmp");

11 Embed Image into Custom Control

12 Script Callbacks Improves UI experience Page is interactive while the server processes request No browser flashing or loss of scroll position Does not add to the navigation history Control developer writes some additional code Modeled after post-back event handling Also implements a script callback function Page framework handles partial page execution

13 Click Init Load State Process Postback Data Load Script Event Handler Script Callback Trigger Async Request Return result of Callback Callbacks ASP.NET RaiseCallbackEvent(…) Async completes GetCallbackResult() Return result Unload Manipulate DOM

14 ClickSubmitInit Load State POST Request Response Process Postback Data IPostBackDataHandler,IPostBackEventHandler Load Postback Events Save State PreRender Render Unload vs. Post-Backs

15 Adding callback support to the control

16 Control State The essential bits of information to allow controls to ensure expected behavior E.g., SelectedIndex, EditIndex, PageIndex on GridView; ReadOnly property on HtmlEditor Separated out of view state Page developer can turn off view state without losing functionality Control state cannot be turned off Controls must opt-in to participate in this mechanism Should store only the essentials, so control state doesn’t become another view state Properties stored in control state should not be saved in view state as well

17 Asynchronous Task Allow a container to register an asynchronous task to the page Container will be notified when task completed, time-out or ended Time Out is defined at the page directive Control developers can alter the rendering based on the async task result

18 Adding Async Task(s) to a control

19 Web Parts in 9 steps 1. Enable Authentication 2. Configure Personalization Database 3. Add a Web Part Page Manager 4. Add Web Part Page Menu (docs) 5. Add WebPart zones 6. Add Controls, set title 7. Add tool zones (optional) Catalog Zone Editor Zone Connections Zone 8. Expose control properties (optional) 9. Implement connections (optional)

20 Web Parts: Connection Interface Defines the communication contract between two Web parts Connection types Provider Control that provides data and schema information Implements a provider connection point [ConnectionProvider] Defines a call back that returns an instance of the interface One provider connection point can connect to any number of consumer connection points of the same type Consumer Control that gets data Implements a consumer connection point [ConnectionConsumer] Defines a call back that gets an instance of the interface One consumer connection point can connect to only one provider connection points of the same type

21 Web Parts: Connection (cont’d) 1. Web Part Manager request interface to the provider 2. Web Part Manager get an interface from a provider 3. Web Part manager give the interface to the consumer 4. Consumer call provider via interface Provider Consumer WebPartManager 1 2 3 4

22 Web Parts: Connection (cont’d) Dynamic connections are done via the browser Static connections are defined by the page developer

23 Implementing Connection Capabilities

24 Web Parts: Editing Auto-generated user interface [WebBrowsable][WebDisplayName][WebDescription] Web Part can add a custom EditorPart to the EditorZone Implement IWebEditable in the control Return a collection of the Editor Parts EditorPartCollection CreateEditorParts(); Create an EditorPart Create a class that Inheritance from EditorPart Override: Public abstract void SyncChanges(); Protected internal abstract bool ApplyChanges();

25 Adding an Editing UI to the Control

26 Web Parts: Personalization Personalization scope SharedPer-user Personalizing data Automatic Add [WebPersonalization] decoration to properties Must have a public get and set accessor, and take no index parameters Manual Implement IPersonsonalizable Provide fine-grained control over how control personalization data is get/set

27 Web Parts: Personalization (cont’d) Receives notification about the orphaned properties Manager property persistence when upgrades to existing controls Implement IVersioningPersonsonalizable If a Web part does not implement IVersioningPersonalizable, orphaned property values will be deleted

28 Adding Personalization and Web Part Versioning

29 TitleTitle VerbsVerbs ChromeChrome ContentContent TitleIconTitleIcon Web Parts: Chrome Developer can create a new Web part rendering Create a chrome class Associate the chrome class to the WebPartZone All Web Parts contained in a WebPartZone will use the same chrome

30 Adding a New Chrome to the Web Part Application

31 Summary Building control and advance features could not be easier Take Advantage of the new powerful framework features Building control and advance features could not be easier Take Advantage of the new powerful framework features

32 Get a 48% Discount on MSDN Universal Now! For a limited time purchase a 12 month MSDN Universal Subscription for $3565+GST (RRP). You will receive updates as they are released for SQL Server, BizTalk Server, Visual Studio, Exchange Server and Windows Server. You will also receive early access to beta products such as Windows Vista and Office 12. Get in now so that when Visual Studio Team System ships you will be upgraded at no cost to one of the new top tier subscriptions: Visual Studio 2005 Team Edition for Software Developers Visual Studio 2005 Team Edition for Software Architects Visual Studio 2005 Team Edition for Software Testers For more details and to find your local reseller visit:


34 We invite you to participate in our online evaluation on CommNet, accessible Friday only If you choose to complete the evaluation online, there is no need to complete the paper evaluation Your Feedback is Important!


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


Download ppt "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."

Similar presentations

Ads by Google