Building Control Extenders using the AJAX Control Toolkit

20
Building Control Extenders using the AJAX Control Toolkit Adam Calderon Application Development Practice Lead

Transcript of Building Control Extenders using the AJAX Control Toolkit

Page 1: Building Control Extenders using the AJAX Control Toolkit

Building Control Extenders using the AJAX Control

Toolkit

Adam Calderon

Application Development Practice Lead

Page 2: Building Control Extenders using the AJAX Control Toolkit

Contact Information

• More info on InterKnowlogy:www.InterKnowlogy.com

• Contact InformationE-mail: [email protected]: 760-930-0075 x274Blog: http://blogs.InterKnowlogy.com/AdamCalderon

• About Adam Calderon• Microsoft MVP – C#• Microsoft UI Server Frameworks Advisory Council• Developer / Author / Speaker / Teacher

Page 3: Building Control Extenders using the AJAX Control Toolkit

Agenda

• Overview of Toolkit• Development Features of the Toolkit• What are going to build?• Working with the

ExtenderControlBase class• Working with the BehaviorBase class• Adding Design Time support• Summary

Page 4: Building Control Extenders using the AJAX Control Toolkit

Control Toolkit Overview

• Shared source project between Microsoft and the community (www.codeplex.com)

• Contains 30+ controls that are ready to use

• Builds on ASP.NET AJAX• Provides a development framework

for building extenders• Increases developer productivity

Page 5: Building Control Extenders using the AJAX Control Toolkit

Toolkit Development Features

• Reliance on attributes to simplify development

• Rich set of .NET classes• Rich set of JavaScript classes• Support for animation• Visual Studio templates• Design Time support

Page 6: Building Control Extenders using the AJAX Control Toolkit

What are we going to build?

• Unlimited Images• Configurable

Rotation Interval• Design Time support

for adding images, setting rotation interval

Features

Page 7: Building Control Extenders using the AJAX Control Toolkit

Building Base Solution Demo

• Create a blank Solution• Add an ASP.NET AJAX Control Project• Add an ASP.NET Web Application

Project• Add AJAX Control Toolkit references

Page 8: Building Control Extenders using the AJAX Control Toolkit

ExtenderControlBase Class

• Merges the server-side experience with the client-side experience

• Builds on functionality provided by ExtenderControl in ASP.NET AJAX

• Relies on attributes to perform ScriptBehaviorDescriptor and ScriptReference assignments

Page 9: Building Control Extenders using the AJAX Control Toolkit

ExtenderControlBase Class Diagram

• Inherits from ExtenderControl• Provides support for ensuring

properties are assigned correctly

• Provides functionality for searching contained controls

• Provides functionality to set and get properties from control viewstate

• Provides support for client state

Page 10: Building Control Extenders using the AJAX Control Toolkit

Script Behavior Attributes

Attribute ScriptBehaviorDescriptor Method

ExtenderControlProperty AddProperty

ExtenderControlEvent AddEvent

ElementReference AddElementProperty

ComponentReference AddComponentProperty

ScriptBehaviorDescriptor descriptor = new ScriptBehaviorDescriptor( "ImageRotatorExtender.ImageRotator", targetControl.ClientID); descriptor.AddProperty("rotationInterval", RotationInterval);

[ExtenderControlProperty]public int RotationInterval{ get { return GetPropertyValue<int>("RotationInterval", 3); } set { SetPropertyValue<int>("RotationInterval", value); }}

Using Attributes (No Override Required)

Using ScriptBehaviorDescriptor in GetScriptDescriptors Override

Page 11: Building Control Extenders using the AJAX Control Toolkit

Script Reference Attributes

Attribute Description

ClientScriptResource Creates a ScriptReference for the specified script

RequiredScript Ensures referenced script is included

ClientCSSResource Includes a CSS file in the control

ClientScriptResource Creates a ScriptReference for the specified script

Using ScriptReference in GetScriptReferences Override

Using Attributes (No Override Required)

ScriptReference( "ImageRotatorExtender.ImageRotator.js", this.GetType().Assembly.FullName);

[ ClientScriptResource("ImageRotator.ImageRotatorBehavior", "ImageRotator.ImageRotatorBehavior.js“)] public class ImageRotatorExtender : ExtenderControlBase { ….. }

Page 12: Building Control Extenders using the AJAX Control Toolkit

ExtenderControlBase Demo

• Adding properties• Exposing properties for behavior

assignment• Dealing with property values

Page 13: Building Control Extenders using the AJAX Control Toolkit

BehaviorBase Class

• Builds upon functionality provided by the ASP.NET AJAX JavaScript classes

• Provides base services for client-side functionality including: • working with client state• asynchronous request events of the

Sys.WebForms.PageRequestManager

Page 14: Building Control Extenders using the AJAX Control Toolkit

JavaScript Classes Diagram

Page 15: Building Control Extenders using the AJAX Control Toolkit

BehaviorBase Demo

• Creating prototype class• Adding properties• Registering class

Page 16: Building Control Extenders using the AJAX Control Toolkit

Design Time Support

• New Extender Wizard in Visual Studio 2008

• Use of System.Web.UI.Design namespace designers

• Use of PersistenceMode attribute• Use of ParseChildren attribute

Page 17: Building Control Extenders using the AJAX Control Toolkit

Design Time Support Demo

• Adding Custom classes to work with Image information

• Adding designer support for adding images

• Adding attributes to enable list of images to be stored inline with the extender

Page 18: Building Control Extenders using the AJAX Control Toolkit

Summary

• Toolkit enhances development experience making hard things easier

• Rich design time support provides a better experience for consumers of your controls

• Added functionality fills the gaps of the standard ASP.NET AJAX APIs

Page 19: Building Control Extenders using the AJAX Control Toolkit

Book on ASP.NET Ajax Development

Page 20: Building Control Extenders using the AJAX Control Toolkit

Contact Information

• More info on InterKnowlogy:www.InterKnowlogy.com

• Contact InformationE-mail: [email protected]: 760-930-0075 x274Blog: http://blogs.InterKnowlogy.com/AdamCalderon

• About Adam Calderon• Microsoft MVP – C#• Microsoft UI Server Frameworks Advisory Council• Developer / Author / Speaker / Teacher