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

Toolkit Version of Custom Control - InterKnowlogy Bloggers

Jul 27, 2015

Download

Documents

Sampetruda
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Toolkit Version of Custom Control - InterKnowlogy Bloggers

Building Control Extenders using the AJAX Control

Toolkit

Adam Calderon

Application Development Practice Lead

Page 2: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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: Toolkit Version of Custom Control - InterKnowlogy Bloggers

What are we going to build?

• Unlimited Images• Configurable

Rotation Interval• Design Time support

for adding images, setting rotation interval

Features

Page 7: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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: Toolkit Version of Custom Control - InterKnowlogy Bloggers

ExtenderControlBase Demo

• Adding properties• Exposing properties for behavior

assignment• Dealing with property values

Page 13: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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: Toolkit Version of Custom Control - InterKnowlogy Bloggers

JavaScript Classes Diagram

Page 15: Toolkit Version of Custom Control - InterKnowlogy Bloggers

BehaviorBase Demo

• Creating prototype class• Adding properties• Registering class

Page 16: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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: Toolkit Version of Custom Control - InterKnowlogy Bloggers

Book on ASP.NET Ajax Development

Page 20: Toolkit Version of Custom Control - InterKnowlogy Bloggers

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