Download presentation
Presentation is loading. Please wait.
Published byAmberly Mathews Modified over 9 years ago
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
3
Agenda Control Framework overview Composite control ScriptOMFocus Web resources Script callback Asynchronous tasks Web Parts – Connection Web Parts – Editing Web Parts – Personalization Web Parts – Chrome
4
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
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 to call EnsureChildControls() 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); Type type, string key, string script, bool addScriptTags); public void RegisterClientScriptInclude( Type type, string key, string url); Type type, string key, string url);
8
Define which control receives focus: Client side Server side Controls can override to delegate focus to a child control if they want explicit control Focus Public void Page.SetFocus(..); SetFocusonError; Control.Focus(..)
9
Creating a Control that Focus of the Page
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(), "ExtendedTextBox.CoffeeBean.bmp");
11
Embed Image and Script Resource into a 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 Callback Event ICallbackEventHandler Script Event Handler Script Callback Trigger Async Request Return result of Callback Unload Callbacks
14
Develop a TextFilter Out-of-Band Control
15
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
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
Adding Async Task to the TextFilter Control
18
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
19
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
20
Web Parts: Connection (cont’d) Dynamic connections are done via the browser Static connections are defined by the page developer
21
Implementing Connection Capabilities to the Text FilterControl
22
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();
23
Adding an Editing UI to the TextFilter Control
24
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
25
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
26
Adding Personalization and Web Part Versioning
27
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
28
Adding a New Chrome to the Web Part Application
29
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
31
Your Feedback is Important! Please Fill Out a Survey for This Session on CommNet
32
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.