320 likes | 517 Views
WEB428 ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 . Andres Sanabria Program Manager Web Platform and Tools Team Microsoft Corporation. Agenda. Control Framework overview Composite control ScriptOM Focus Web resources Script callback Asynchronous tasks
E N D
WEB428 ASP.NET 2.0: Advanced Server Controls and Web Parts with ASP.NET 2.0 Andres Sanabria Program Manager Web Platform and Tools Team Microsoft Corporation
Agenda • Control Framework overview • Composite control • ScriptOM • Focus • Web resources • Script callback • Asynchronous tasks • Web Parts – Connection • Web Parts – Editing • Web Parts – Personalization • Web Parts – Chrome
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
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 to call EnsureChildControls() • Associated designer ensures child controls are created at design-time as well
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 <script> 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);
Focus • Define which control receives focus: • Client side • Server side • Controls can override to delegate focus to a child control if they want explicit control • <form defaultfocus="foo1“ .. > • Public void Page.SetFocus(..); • SetFocusonError; Control.Focus(..)
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(), "ExtendedTextBox.CoffeeBean.bmp");
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
Async Request Trigger Return result of Callback Callback Event ICallbackEventHandler Callbacks Script Event Handler Click Script Callback Init Load State Process Postback Data Load Unload
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
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
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 • 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 • 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
Web Parts: Connection (cont’d) • Web Part Manager request interface to the provider • Web Part Manager get an interface from a provider • Web Part manager give the interface to the consumer • Consumer call provider via interface WebPartManager 1 3 2 Consumer Provider 4
Web Parts: Connection (cont’d) • Dynamic connections are done via the browser • Static connections are defined by the page developer
Implementing Connection Capabilities to the Text FilterControl
Web Parts: Editing • Auto-generated user interface • [WebBrosable] • [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();
Web Parts: Personalization • Personalization scope • Shared • Per-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
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
Title TitleIcon Verbs Chrome Content 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
Summary • Building control and advance features could not be easier • Take Advantage of the new powerful framework features
Your Feedbackis Important! Please Fill Out a Survey forThis Session on CommNet
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.