1 / 32

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

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

armina
Download Presentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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

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

  5. Creating a Composite Control

  6. 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);

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

  8. Creating a Control that Focus of the Page

  9. 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");

  10. Embed Image and Script Resource into a Custom Control

  11. 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

  12. 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

  13. Develop a TextFilter Out-of-Band Control

  14. 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

  15. 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

  16. Adding Async Task to the TextFilter Control

  17. 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

  18. 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

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

  20. Implementing Connection Capabilities to the Text FilterControl

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

  22. Adding an Editing UI to the TextFilter Control

  23. 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

  24. 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

  25. Adding Personalization and Web Part Versioning

  26. 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

  27. Adding a New Chrome to the Web Part Application

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

  29. Your Feedbackis Important! Please Fill Out a Survey forThis Session on CommNet

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

More Related