Download the sample pages.pdf

69

Transcript of Download the sample pages.pdf

Page 1: Download the sample pages.pdf
Page 2: Download the sample pages.pdf

Many of the designations used by manufacturers andsellers to distinguish their products are claimed astrademarks. Where those designations appear in thisbook, and the publisher was aware of a trademarkclaim, the designations have been printed with initialcapital letters or in all capitals.

The .NET logo is either a registered trademark ortrademark of Microsoft Corporation in the UnitedStates and/or other countries and is used under licensefrom Microsoft.

The authors and publisher have taken care in thepreparation of this book, but make no expressed orimplied warranty of any kind and assume no respon-sibility for errors or omissions. No liability is assumedfor incidental or consequential damages in connectionwith or arising out of the use of the information or pro-grams contained herein.

The publisher offers excellent discounts on this bookwhen ordered in quantity for bulk purchases or specialsales, which may include electronic versions and/orcustom covers and content particular to your business,training goals, marketing focus, and branding inter-ests. For more information, please contact:

U.S. Corporate and Government Sales(800) [email protected]

For sales outside the United States please contact:

International [email protected]

Visit us on the web: www.informit.com/aw

Library of Congress Cataloging-in-Publication Data:

Calderon, Adam, 1964-Advanced ASP.Net Ajax server controls for .Net 3.5

/ Adam Calderon, Joel Rumerman.p. cm.

ISBN 0-321-51444-0 (pbk. : alk. paper) 1. Internetprogramming. 2. Active server pages. 3. Microsoft.NET. 4. Ajax (Web site development technology) 5.Web servers. I. Rumerman, Joel, 1980- II. Title.

QA76.625.C34 2008006.7’882—dc22

2008013462

Copyright © 2009 Pearson Education, Inc.

All rights reserved. Printed in the United States ofAmerica. This publication is protected by copyright,and permission must be obtained from the publisherprior to any prohibited reproduction, storage in aretrieval system, or transmission in any form or by anymeans, electronic, mechanical, photocopying, record-ing, or likewise. For information regarding permis-sions, write to:

Pearson Education, Inc.Rights and Contracts Department501 Boylston Street, Suite 900Boston, MA 02116Fax (617) 671 3447

ISBN-13: 978-0-321-51444-8ISBN-10: 0-321-51444-0Text printed in the United States on recycled paper atRR Donnelly in Crawfordsville, Indiana. First printing: July 2008

This Book Is Safari Enabled

The Safari® Enabled icon on the cover of your favoritetechnology book means the book is available throughSafari Bookshelf. When you buy this book, you get freeaccess to the online edition for 45 days.

Safari Bookshelf is an electronic reference library thatlets you easily search thousands of technical books,find code samples, download chapters, and accesstechnical information whenever and wherever youneed it.

To gain 45-day Safari Enabled access to this book:

• Go to http://www.informit.com/onlineedition.

• Complete the brief registration form.

• Enter the coupon code DWNQ-VHHL-H21A-XGL8-34YC.

If you have difficulty registering on Safari Bookshelf or accessing the online edition, please e-mail [email protected].

Editor-in-ChiefKaren Gettman

Acquisitions EditorJoan Murray

Development EditorsSheri CainChris Zahn

Managing EditorKristy Hart

Project EditorJovana San Nicolas-Shirley

Copy EditorKeith Cline

IndexerWordWise Publishing Services

ProofreaderGeneil Breeze

Publishing CoordinatorOlivia Basegio

Cover DesignerChuti Prasertsith

CompositorBronkella Publishing

Page 3: Download the sample pages.pdf

Foreword

TH E ASP.NET P L AT F O R M P O W E R S millions of websites around theworld today, and is perhaps one of the most productive platforms for webdevelopment. During the nearly ten years of its development and use,ASP.NET has formed around itself a strong community and vibrant ecosys-tem of developers.

The page framework and the associated server controls framework arequintessential to the success of ASP.NET and its developer experience, pro-gramming model, and extensibility. Writing this Foreword brings backmemories of early ASP.NET days, and reminds me of the continued evolu-tion of the framework as a platform alongside the Web.

In the late 1990s, the Web was very much a nascent application platform.Browsers brought potential for new levels of reach, but offered few andvarying degrees of capabilities (remember HTML 3.2?), and concepts suchas “stateless programming model” presented an odd paradigm shift. Servercontrols provided a set of familiar abstractions and created a component-based rapid application development (RAD) programming experience forthe Web (à la Visual Basic) and allowed developers to feel at home as theystarted to look to the Web to build the next generation of data-driven appli-cations.

Flash forward a few years, and in 2006, the AJAX buzz created arenewed interest in the Web as the application platform. Today, AJAX ismainstream and, quite literally, everywhere. It enables building interactiveexperiences that users have come to expect. Still, it brings new but similar

xxv

Page 4: Download the sample pages.pdf

challenges: varying browser APIs and an unfamiliar script-based pro-gramming model. Once again, ASP.NET (and in particular, server controls)provided a mechanism for creating a productive development model forincorporating AJAX-based techniques, and for encapsulating server andclient behaviors into a familiar and consistent component model.

ASP.NET provides an end-to-end AJAX story. Traditional server con-trols create a simple server-centric AJAX programming model, but they arejust a part of the story. This new generation of server controls leverages anAJAX script framework that independently enables a client-centric AJAXprogramming model. The core framework is complemented by the AJAXControl Toolkit, which offers both a compelling set of out-of-the-box com-ponents and an open source project for further developing the ASP.NETAJAX stack. I am excited to see this end-to-end story uncovered and unfolditself over the course of this book.

In this book, Adam and Joel focus on providing a beyond-the-basics drilldown of the inner workings and extensibility of the ASP.NET AJAX frame-work by covering the programming patterns established by the scriptframework, the architecture, and the techniques to create AJAX-enabledserver controls. They also cover advanced but still relevant topics such aslocalization and error handling. By providing a conceptual guide to under-standing and extending the framework, this book is sure to serve any appli-cation or component developer who is looking to unlock the true potentialof ASP.NET AJAX.

—Nikhil KothariSoftware Architect.NET Developer Platform, Microsoft

Forewordxxvi

Page 5: Download the sample pages.pdf

Preface

Introduction

SE RV E R C O N T R O L S A R E A N I N T E G R A L aspect of every ASP.NET applica-tion we build. They encapsulate browser appearance and server function-ality in a reusable object. They can be used across multiple pages within asingle ASP.NET application and across multiple ASP.NET applications.ASP.NET comes with a lot of prebuilt server controls. We have simple con-trols such as the label, and we have complex controls such as the GridView.We can also create our own server controls to meet a need not met by one ofthe existing controls by inheriting from the appropriate base class and over-riding its methods as needed.

This model of using server controls to encapsulate browser appearanceand server functionality has served our needs well since the inception ofASP.NET 1.0, but our server control needs are changing.

A new server control need that has recently surfaced is the ability toincorporate AJAX functionality directly into the server control.

This need arose because our web applications need to be more respon-sive and visually interactive than the traditional ASP.NET repaint-the-entire-screen model and therefore the traditional server control supplies.This requirement has emerged because users are using websites such asGmail, Live.com, Yahoo! Mail, and others that don’t repaint the screenevery time they click a button or need to receive fresh data. Rather, they rely

xxvii

Page 6: Download the sample pages.pdf

on AJAX to fetch fresh data and then update or add to a portion of thescreen based on that data. Because these websites are heavily used andusers really enjoy their experience while using these websites, they expectother websites to perform with the same elegance as their favored sites do.When a website doesn’t perform with the same elegance, the user oftenmoves on to another website that does. Those popular applications haveraised the bar for what is an acceptably user-friendly website.

Because our users are demanding a website experience that essentiallyuses AJAX and we build our ASP.NET websites using server controls, weneed a way of easily creating server controls that not only encapsulatebrowser appearance and server functionality, but also include AJAX func-tionality so that the server control itself is AJAX-enabled.

Taking a step back for a moment, unlike other technologies you mighthave read books about, ASP.NET AJAX server controls don’t provide youwith anything that you couldn’t already do. We’ve always been able toembed AJAX functionality into server controls… it was just a real pain.

There were a few different methods we could use to include theJavaScript with our server control such as embedding it as a resource, butwe eventually ended up having to do the same three tasks. To make ourserver control have some serious client capabilities, we always had to con-catenate strings together to form JavaScript statements and functions, writebrowser sniffing statements to make sure that the JavaScript was cross-browser compatible, and add attributes or render out HTML that attachedthe JavaScript functionality to the client versions of our server controls. Itwasn’t impossible, but it was error-prone, and there was always this min-gling of server code and JavaScript that was hard to maintain and evenharder to read.

Furthermore, if you had multiple server controls that had client capa-bilities, it was difficult (but not impossible) to ensure that the client func-tions that each server control required didn’t overwrite each other whenrendered on the browser. Tracking down that problem was always a funhour or so.

The difficulty grew exponentially if we wanted to include a mechanismfor asynchronously communicating with the server when the user pressed

Prefacexxviii

Page 7: Download the sample pages.pdf

a button embedded in the server control. Even with a helper communica-tion library, there were always tricks to getting your control to communi-cate properly with the server.

These hindrances were problematic enough to lead to some bad pro-gramming habits and bad code and to scare programmers away from evenattempting to include AJAX functionality in their server controls.

These problems are what Microsoft ASP.NET AJAX solves. In this book, we teach you how to use ASP.NET AJAX to create server

controls that encapsulate AJAX functionality. ASP.NET AJAX provides bothserver and client programming constructs that make adding AJAX capa-bilities to our server controls easy. Not to sound cliché, but with ASP.NETAJAX reducing the complexity of adding AJAX capabilities to our servercontrols, we can create server controls whose AJAX capabilities are limitedonly by our creativity. If we want a listbox that self-updates with fresh data,if we want a type-ahead textbox that dynamically populates from theserver, or if we want a button that submits an address for verification, wecan easily accomplish these things through ASP.NET AJAX.

The ASP.NET AJAX Components

As we go through the book we’ll be talking about the three parts ofASP.NET AJAX: the Microsoft AJAX Library, the ASP.NET 2.0 AJAX Exten-sions, and the ASP.NET AJAX Control Toolkit. Here’s a quick rundown ofthe different components.

Microsoft AJAX LibraryThe Microsoft AJAX Library is the JavaScript programming framework ofASP.NET AJAX. It provides all the client programming constructs you’lluse to create new client objects and components. It’s contained within the MicrosoftAjax.js JavaScript file that’s embedded in the System.Web.Extensions DLL.

Preface xxix

Page 8: Download the sample pages.pdf

ASP.NET 2.0 AJAX ExtensionsThe ASP.NET 2.0 AJAX Extensions are server objects such as the ScriptManager, ScriptControl, and ScriptDescriptor, which provide a connec-tion between the Microsoft AJAX Library and our server ASP.NET devel-opment. These server objects provide an important distinction betweenASP.NET AJAX and other AJAX frameworks because they provide a serverprogramming model for manipulating client code (and allow us to makeAJAX-enabled server controls!). Like the Microsoft AJAX Library, they areincluded in the System.Web.Extensions DLL.

ASP.NET AJAX Control ToolkitThe ASP.NET AJAX Control Toolkit is a shared source project that is builton top of ASP.NET AJAX. It’s an effort shared between Microsoft and theASP.NET AJAX community with the goal of developing powerful andreusable ASP.NET AJAX extenders and controls.

It’s not actually part of ASP.NET AJAX, but because it provides so manygreat server and extender controls, it’s invaluable to the ASP.NET AJAXcommunity. Creating new extender controls through it is a topic we coverfully.

Book Breakdown

The book is divided into four major parts. In the first part, we focus on thebasics of the Microsoft AJAX Library and JavaScript, the programming lan-guage that powers it. We call this part “Client Code.” In the second part, wefocus on a creating distributable AJAX-enabled controls, and we call thispart “Controls.” In the third part, called “Communication,” we focus on thedifferent ways your client control can communicate with the server. Finally,in the fourth part, we focus on the AJAX Control Toolkit, a slightly higher-level model of creating AJAX-enabled server controls. This final part isaptly named “AJAX Control Toolkit.”

Client CodeChapter 1, “Programming with JavaScript,” focuses on JavaScript, the pro-gramming language that powers the Microsoft AJAX Library. We spend a

Prefacexxx

Page 9: Download the sample pages.pdf

full chapter on JavaScript because so many developers (ourselves included)have glossed over key details when working with the language; andbecause you’re going to be writing so much JavaScript to AJAX-enable yourserver controls, a solid background is important.

In Chapter 2, “Microsoft AJAX Library Programming,” we continuewhere we left off in Chapter 1 by taking a look at how the Microsoft AJAXLibrary builds on JavaScript to provide a programming platform a .NETdeveloper will find familiar.

ControlsStarting in Chapter 3, “Components,” we begin our path to creating fullyencapsulated AJAX-enabled controls by learning how to use and derivefrom three key client types: components, controls, and behaviors. We talktheory and provide a couple of practical examples.

In Chapter 4, “Sys.Application,” we cover maybe the most importantportion of the Microsoft AJAX Library as we discuss Sys.Application andhow it acts like a client runtime with which we can interact.

In Chapter 5, “Adding Client Capabilities to Server Controls,” we bringthe server into the mix when we cover how to create server componentsthat automatically create corresponding components.

In Chapter 6, “ASP.NET AJAX Localization,” we continue adding con-trol capabilities with an in-depth examination of localization in ASP.NETAJAX.

Finally, in Chapter 7, “Control Development in a Partial Postback Envi-ronment,” we wrap up the “Controls” part with a look at the concerns sur-rounding how the UpdatePanel affects control development.

CommunicationWith Chapter 8, “ASP.NET AJAX Communication Architecture,” we startlooking at communication in ASP.NET AJAX using Windows Communi-cation Foundation (WCF) services, page methods, and the client web serv-ice proxies.

In Chapter 9, “Application Services,” we cover the application servicesand include a demonstration of how to build your own application service.

Preface xxxi

Page 10: Download the sample pages.pdf

AJAX Control ToolkitBeginning with Chapter 10, “ASP.NET AJAX Control Toolkit Architecture,”we start our look at the AJAX Control Toolkit. We cover the base classes thatare used by toolkit controls and the support and designer classes that pro-vide additional features.

Finally, we conclude the book with Chapter 11, “Adding Client Capa-bilities to Server Controls Using the ASP.NET AJAX Control Toolkit,” as weattach client capabilities to server controls using the AJAX Control Toolkit.This chapter includes how to build a new extender control and providedesign-time features for it.

What Is Not Covered?

You might find it strange to see a note that talks about what we’re not cov-ering. We’re including it for two reasons.

First, this book covers a pretty narrow topic when compared toASP.NET AJAX at large. Because of this, we don’t have the normal intro-ductory chapter where we walk you through the basics or history ofASP.NET AJAX. Instead, we’re making the assumption, good or bad, thatyou’ve got some ASP.NET AJAX knowledge under your belt. If you don’t,don’t worry; getting your ASP.NET AJAX knowledge to the point whereyou feel comfortable doesn’t take long, and this book will pick up rightwhere that basic knowledge leaves off. For this type of information, theMicrosoft ASP.NET AJAX website located at http://asp.net/ajax is anexcellent source.

Second, we’re leaving out a familiar ASP.NET AJAX subject, and wewanted a chance to tell you and defend our decision before we got too far.This is something that we’ve repeatedly debated between the two of us andasked many colleagues for their opinion and was a decision that we didn’tcome to easily.

There are no chapters in which we cover how to use the UpdatePanelserver control.

Okay, you haven’t closed the book? Good. Let us explain how and whywe came to this decision.

Prefacexxxii

Page 11: Download the sample pages.pdf

Simply put, the UpdatePanel is a server control. It comes with ASP.NETAJAX and provides a quick and dirty way to refresh a portion of a pagesuch that the page goes through its normal lifecycle, but doesn’t refresh theentire page when the page processing is done. Using it, we don’t have toalter the way we’ve been programming web pages since ASP.NET 1.0 cameout. This is a good thing and was a “quick win” for Microsoft. It allowedASP.NET AJAX to be adopted quickly by ASP.NET developers and pro-vided a unique advantage against other AJAX frameworks.

However, the UpdatePanel is just a server control and it’s developed insuch a way that it doesn’t have a whole lot of comparative properties withthe type of ASP.NET AJAX server control development we’re covering.

We’re not saying it’s not an important server control and that it has noplace in the AJAX world. Rather, it is an extremely valuable tool whosecomplexity and correct usage is worthy of a small book; just not this one.

Finally, although we do not cover how to use the UpdatePanel, we docover how to create server controls so that they work correctly in anUpdatePanel, or more specifically a partial-postback, environment. Weexpect that you want your new server controls to work in any ASP.NETenvironment, and a partial-postback environment is no exception. The par-tial-postback environment, however, requires us to use some differentmethods, the new ScriptManager.RegisterXXX methods being the mostcommon, and take some care in how we create our server controls. So,we’ve dedicated Chapter 7 to this topic.

Why Just Server Controls?

Writing a book on just server controls allows us to delve deeply into a nar-row topic that is extremely important to web application developers. TheASP.NET AJAX books currently available all generally focus on the tech-nology as a whole. Because they cover a broad range of topics, giving a tasteof everything, they have trouble really getting into how certain parts ofASP.NET AJAX work and tend to give shallow coverage of topics that wethink are key to creating server controls. It’s been our experience that devel-opers tend to move past the content of the more general books fairly

Preface xxxiii

Page 12: Download the sample pages.pdf

quickly because nonbasic situations arise almost immediately when work-ing on a real-life web application.

Target Audience

This book is primarily targeted at the experienced ASP.NET developer whohas developed custom web server controls. We expect that you’re readingthis book to enhance your already proficient ASP.NET development skillset with new ASP.NET AJAX skills. The applications you develop demandelegance and professionalism and easy maintenance and scalability, so youtend to use server controls to your advantage wherever possible.

Besides your experience with ASP.NET, we expect that you’re familiarwith JavaScript and the basics of ASP.NET AJAX. Therefore, we don’t coverhow to set up a new ASP.NET AJAX-enabled web application, andalthough we do cover JavaScript, we start our coverage at a level where weassume some existing knowledge.

Our goal is to provide you with the tools you need to build reusableASP.NET AJAX server controls or AJAX Control Toolkit extender controls.Our feeling is that reasonably knowledgeable ASP.NET developers will beable to learn the skills necessary to create new ASP.NET AJAX server con-trols through this book and then add that skill to their ASP.NET develop-ment tool bag.

Prerequisites

This book requires ASP.NET 3.5 AJAX and Visual Studio 2008. We heavilycover features included in ASP.NET 3.5 AJAX not included in ASP.NET 2.0AJAX and C#’s and Visual Studio 2008’s new capabilities such as automaticproperties and JavaScript IntelliSense.

Source Code

The source code for the book’s examples can be found on the book’s web-site: www.informit.com/title/9780321514448.

Prefacexxxiv

Page 13: Download the sample pages.pdf

11 Adding Client Capabilities toServer Controls Using theASP.NET AJAX Control Toolkit

I N T H E P R E C E D I N G C H A P T E R , we covered the architecture of the AJAXControl Toolkit, describing at a high level what it has to offer and the

attributes, classes, and interfaces that make it all happen. The enhancedfunctionality you get in the toolkit, from attribute-based programming torich animations, provides a compelling alternative to coding against theASP.NET 2.0 AJAX Extensions and the Microsoft AJAX Library directly. Inthis chapter, we delve into the details of the toolkit a little further as wedevelop as series of extender controls that demonstrate the rich features thetoolkit provides.

Adding Client-Side Behavior Using the ExtenderControlBase

The ASP.NET AJAX Control Toolkit provides many features to assist in thedevelopment of extender controls, such as the automatic creation of $create statements, the use of attributes to decorate extender control prop-erties that should be included in the $create statement creation, built-in

513

Page 14: Download the sample pages.pdf

designer support, and many more. In this section, we revisit the ImageRotator extender we created in Chapter 5, “Adding Client Capabilities toServer Controls,” and re-create it using the ASP.NET AJAX Control Toolkit. This approach enables us to compare the alternatives as we build the newextender.

The process of building an extender control using the ASP.NET AJAXControl Toolkit consists of four main steps.

1. Create the template classes.

2. Provide implementation for the inherited extender control class.

3. Provide implementation for the Sys.UI.BehaviorBase-basedJavaScript class.

4. Attach the extender control to an existing server control.

Visual Studio 2008 Extender Control Library TemplateThe ASP.NET AJAX Control Toolkit comes with full support for Visual Studio 2008 in the form of a project template that is geared toward creatingan extender control library project. The template, shown in Figure 11.1, cre-ates a library project structure (see Figure 11.2) that contains an extendercontrol class, a designer class, and a JavaScript behavior class. In this sec-tion, we look at the ImageRotatorExtender.cs, ImageRotatorDesigner.cs,and ImageRotatorBehavior.js files that the template generated for us as webegin to discuss creating a new and improved ImageRotator extender.

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

514

NOTE Additional Template

The toolkit also comes with a template that generates the same filesthat can be used when you need to add additional extenders to anexisting project, which can be found when you select Add New Itemfrom a project.

Page 15: Download the sample pages.pdf

Figure 11.1 Extender control project template

Adding Client-Side Behavior Using the ExtenderControlBase 515

Figure 11.2 Extender control project template structure

Page 16: Download the sample pages.pdf

The ImageRotatorExtender class shown in Listing 11.1 serves as the basisfor our ImageRotator extender control. The class inherits from ExtenderControlBase and provides a template that contains most of the requiredentries for us, such as the web resource registration of our associated behav-ior class, class attributes that associate the designer for the extender, the client script to be downloaded, and the target type for the extender. The template also creates a default property, demonstrating the use of the ExtenderControlProperty and DefaultValue attributes and the use of the GetPropertyValue method inside the property setter and getter.

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

516

NOTE GetPropertyValue Method Version

The version of the GetPropertyValue method used by the template isan outdated one. When building out the class, we will change theimplementation to use the GetPropertyValue<T> version instead.

Listing 11.1 ImageRotatorExtender Class

[assembly: System.Web.UI.WebResource("ImageRotator.ImageRotatorBehavior.js","text/javascript")]namespace ImageRotator{[Designer(typeof(ImageRotatorDesigner))][ClientScriptResource("ImageRotator.ImageRotatorBehavior","ImageRotator.ImageRotatorBehavior.js")]

[TargetControlType(typeof(Control))]public class ImageRotatorExtender : ExtenderControlBase{[ExtenderControlProperty][DefaultValue("")]public string MyProperty{get{return GetPropertyValue("MyProperty", "");

}set{SetPropertyValue("MyProperty", value);

}}

}}

Page 17: Download the sample pages.pdf

The ImageRotatorDesigner class shown in Listing 11.2 will be thedesigner class for our ImageRotator extender control. The designer classprovides default designer functionality for our extender control duringdesign time. We associate the designer with our ImageRotatorExtenderclass by using the Designer attribute, which is automatically added whenwe use the template. The ExtenderControlBaseDesigner<T> class that theImageRotatorDesigner class inherits from makes it possible for the prop-erties of our extender control to show up in the Properties window whilethe design-time focus is on the image control we are extending. This defaultbehavior provides a more efficient way of working with extenders and thecontrols they are extending.

Listing 11.2 ImageRotatorDesigner Class

namespace ImageRotator{class ImageRotatorDesigner : AjaxControlToolkit.Design.ExtenderControlBaseDesigner<ImageRotatorExtender>

{}

}

The ImageRotatorBehavior class shown in Listing 11.3 will be the client-side behavior class for our ImageRotator extender control. The class con-sists of the same structure we used in Chapter 5, but now inherits from theAjaxControlToolkit.BehaviorBase class, which provides added function-ality for working with client state and interacting with the asynchronousrequest events of the Sys.WebForms.PageRequestManager.

Listing 11.3 ImageRotatorBehavior Class

/// <reference name="MicrosoftAjaxTimer.debug.js" />/// <reference name="MicrosoftAjaxWebForms.debug.js" />/// <reference name="AjaxControlToolkit.ExtenderBase.BaseScripts.js"

assembly="AjaxControlToolkit" />

Type.registerNamespace('ImageRotator');

ImageRotator.ImageRotatorBehavior = function(element) {ImageRotator.ImageRotatorBehavior.initializeBase(this, [element]);

Adding Client-Side Behavior Using the ExtenderControlBase 517

Page 18: Download the sample pages.pdf

Listing 11.3 continued

// TODO : (Step 1) Add your property variables herethis._myPropertyValue = null;

}

ImageRotator.ImageRotatorBehavior.prototype = {initialize : function() {ImageRotator.ImageRotatorBehavior.callBaseMethod(this,'initialize');// TODO: Add your initialization code here

},

dispose : function() {// TODO: Add your cleanup code hereImageRotator.ImageRotatorBehavior.callBaseMethod(this, 'dispose');

},

// TODO: (Step 2) Add your property accessors hereget_MyProperty : function() {return this._myPropertyValue;

},set_MyProperty : function(value) {this._myPropertyValue = value;

}}

ImageRotator.ImageRotatorBehavior.registerClass('ImageRotator.ImageRotatorBehavior', AjaxControlToolkit.BehaviorBase);

Inheriting from the ExtenderControlBase ClassThe ASP.NET AJAX Control Toolkit comes with its own version of the System.Web.UI.ExtenderControl class, which provides additional func-tionality that supports the development pattern the toolkit is designed towork with. The AjaxControlToolkit.ExtenderControlBase class providesthe inheritor support for serialization of property values, support for work-ing with the toolkit-based attributes, seamless integration with control-based view state, support for working with client state, and the ability tospecify an alternate script path for debugging and working with themes.The ImageRotatorExtender class in Listing 11.4 shows a much different-looking class than we saw in Chapter 5. The class no longer requires over-rides for the GetScriptDescriptors and GetScriptReferences methods,it has class-level attributes, it has property-level attributes, and the propertysetters and getters are referencing their values through a method. So, let’s

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

518

Page 19: Download the sample pages.pdf

go over these changes and see how we develop an extender control build-ing on the structure the template provided for us.

The setting of the assembly-based WebResource attribute in our extenderclass is a pattern that all the extenders and script controls in the toolkit fol-low. This pattern helps centralize all the pieces for the component in onelocation instead of having to add an entry to the assembly when a new con-trol is added to the toolkit. The attributes applied to the class that we coverin this section are the Designer, ClientScriptResource, RequiredScript,and TargetControlType attributes. The Designer attribute is used to spec-ify the class that will provide design-time services to our extender. TheClientScriptResource attribute is used to include the client-side scripts forour extender and consists of the resource type and the full resource nameand should refer to an embedded resource. The RequiredScriptResourceattribute brings in the timer script file that is associated with the TimerScript class that we will use in our behavior class. Finally, the TargetControlType attribute is used to limit the types of controls our extender canbe associated with.

The RotationInterval and ImageList properties of our class have alsochanged with the use of attributes and the reliance on the GetPropertyValue<T> and SetPropertyValue<T> methods to access our property data.The ExtenderControlProperty attribute is used to indicate that the prop-erty should be added to the ScriptComponentDescriptor as a property andlater included in the $create statement that creates the behavior class onthe client. The ClientPropertyName attribute is used to change the name of the property that is used when the property is added to the ScriptComponentDescriptor from the default value of the property name to thename provided to the attribute. The DefaultValue attribute, which comesfrom the System.CompnentModel namespace, is used to indicate to design-ers and code generators the default value of the property. The ExtenderControlBase class provides the GetPropertyValue<T> and GetProperty

Value<T> generic methods that get and set the property value directly fromthe control view state. By using these methods in our property setters andgetters, a consumer of our extender can work with it in the designer, declar-atively in the HTML editor, or in code and be assured that during a post-back the values will be available.

Adding Client-Side Behavior Using the ExtenderControlBase 519

Page 20: Download the sample pages.pdf

Listing 11.4 ImageRotatorExtender Class

[assembly:System.Web.UI.WebResource("ImageRotator.ImageRotatorBehavior.js","text/javascript")]namespace ImageRotator{[ParseChildren(true, "ImageList")][Designer(typeof(ImageRotatorDesigner))][ClientScriptResource("ImageRotator.ImageRotatorBehavior",

"ImageRotator.ImageRotatorBehavior.js")][RequiredScript(typeof(TimerScript))][TargetControlType(typeof(Image))]public class ImageRotatorExtender : ExtenderControlBase{[ExtenderControlProperty][ClientPropertyName("rotationInterval")][DefaultValue(3), DisplayName("RotationInterval(seconds))")][DesignerSerializationVisibility( DesignerSerializationVisibility.Visible)]

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

}

private ImageUrlList _imageList;[ExtenderControlProperty][ClientPropertyName("imageList")][DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

[PersistenceMode(PersistenceMode.InnerDefaultProperty)]public ImageUrlList ImageList{get{if (_imageList == null){

_imageList = GetPropertyValue<ImageUrlList>("ImageList", null);if (_imageList == null){

_imageList = new ImageUrlList();SetPropertyValue<ImageUrlList>("ImageList", _imageList);

}}return _imageList;

}}

}}

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

520

Page 21: Download the sample pages.pdf

Creating the AjaxControlToolkit.BehaviorBase ClassThe ASP.NET AJAX Control Toolkit comes with its own version of theSys.UI.Behavior class, which provides additional functionality and sup-ports the development pattern the toolkit is designed to work with. TheAjaxControlToolkit.BehaviorBase class provides inheritor support forworking with client state and interacting with the asynchronous requestevents of the Sys.WebForms.PageRequestManager. The support for workingwith client state is provided by the get_ClientState and set_ClientState

methods that can be used to work with the string-based hidden field asso-ciated with your extender. The class also provides two methods tied to thebeginRequest and endRequest events of the PageRequestManager, whichcan be overridden to provide specific functionality in your behavior in sit-uations where an UpdatePanel is being used.

The ImageRotatorBehavior class shown in Listing 11.5 inherits from theBehaviorBase class and provides the client-side behavior for our extendercontrol. The structure of this class is exactly the same as in Chapter 5, withthe rotationInterval property used to set the interval at which the imageswill be swapped out and the imageList property containing an array of theimages. The one change to the class is in the use of the Sys.Timer class,which is part of the ASP.NET AJAX Control Toolkit. This class, which iscontained in the Compat/Timer folder, wraps the window.setInterval call,providing a cleaner interface for this timer-specific functionality. TheSys.Timer class is just one of many that come with the toolkit that provideadded functionality to the existing Microsoft AJAX Library. If you look inthe Compat and Common folders in the toolkit library project, you will findclasses for working with dates, drag and drop, and threading, just to namea few.

Listing 11.5 ImageRotator Behavior Class

Type.registerNamespace('ImageRotator');

ImageRotator.ImageRotatorBehavior = function(element) {ImageRotator.ImageRotatorBehavior.initializeBase(this, [element]);

this._imageIndex = 0;this._imageList = new Array();this._rotationInterval = null;this._timer = null;

Adding Client-Side Behavior Using the ExtenderControlBase 521

Page 22: Download the sample pages.pdf

Listing 11.5 continued

}ImageRotator.ImageRotatorBehavior.prototype = {initialize : function() {ImageRotator.ImageRotatorBehavior.callBaseMethod(this, 'initialize');

var element = this.get_element();

if(this._imageList){this._imageList =Sys.Serialization.JavaScriptSerializer.deserialize(this._imageList);

this._imageList[this._imageList.length] = element.src;}

if(this._rotationInterval == null)this._rotationInterval = 3;

if(this._timer == null)this._timer = new Sys.Timer();

this._timer.set_interval(this._rotationInterval * 1000);this._timer.add_tick(Function.createDelegate(this, this._rotateImage));

this._timer.set_enabled(true);},

dispose : function() {ImageRotator.ImageRotatorBehavior.callBaseMethod(this, 'dispose');if (this._timer) {this._timer.dispose();this._timer = null;

}

this._imageList = null;

},get_rotationInterval: function(){return this._rotationInterval;

},set_rotationInterval: function(value){this._rotationInterval = value;

},get_imageList: function(){return this._imageList;

},

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

522

Page 23: Download the sample pages.pdf

set_imageList: function(value){this._imageList = value;

},_rotateImage: function(){var element = this.get_element();if(element){element.src = this._imageList[this._imageIndex++];if(this._imageIndex > this._imageList.length - 1)this._imageIndex = 0;

}}

}ImageRotator.ImageRotatorBehavior.registerClass('ImageRotator.ImageRotatorBehavior', AjaxControlToolkit.BehaviorBase);

Attaching the Extender to a ControlYou can attach the ImageRotator extender to an image control by using thenew Extender Control Wizard (see Figure 11.3) that comes with Visual Studio 2008 and thus provide the same design-time experience we saw inChapter 5. The wizard is available from the smart tag of the image controlby selecting the Add Extender option, which opens the wizard. The wiz-ard enables the user to select an extender control from a list and associateit with a control. In our case, we would select the ImageRotator extenderto associate it with the image control. After we do that, we add values to theRotationInterval property and ImageList property using the Propertieswindow of the image control.

Final ThoughtsIf we compare our experience of creating extender controls using theASP.NET AJAX Control Toolkit to using the classes provided by theASP.NET 2.0 AJAX Extensions, we can see that our development experi-ence is much simpler. The use of attributes to register our properties to beincluded in the $create statements and to register our associated script filesdramatically reduces the complexity of our code compared to implement-ing logic in the GetScriptDescriptors and GetScriptReferencesmethods.This convenience alone makes it worth using the toolkit, but if we tack onthe added design-time features, support for working with client state, andthe numerous added JavaScript files such as the Sys.Timer class, the

Adding Client-Side Behavior Using the ExtenderControlBase 523

Page 24: Download the sample pages.pdf

reasons to switch get greater. The use of the toolkit can be compared to theuse of the ActiveX Template Library (ATL) that was used to create ActiveXcontrols in C++. The template provided a ton of base classes and Visual Studio templates that made creating them a lot easier.

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

524

Figure 11.3 Extender Control Wizard

Adding Design-Time Support to Your Extender Control

The introduction of the Extender Wizard in Visual Studio 2008 hasenhanced the design-time experience with regard to working with extendercontrols, and this section explains how to add design-time features of yourown to give your controls that professional feel that users have becomeaccustomed to.

Page 25: Download the sample pages.pdf

Default Design-Time ExperienceThe ImageRotatorDesigner class shown in Listing 11.2 provides everythingwe need to get a basic design-time experience for our extender control. TheExenderControlBaseDesigner<T> that it inherits from makes it possible forthe properties of our extender control to show up in the Properties windowwhile the design-time focus is on the image control we are extending. Fig-ure 11.4 shows the RotationInterval and ImageList properties that appearin the Properties window while the image control has focus in the designer.This default feature addresses one issue, which is being able to work withthe ImageRotator properties in an integrated way, but still does not addressthe issue of data entry for the properties themselves and how that experi-ence can be enhanced.

Adding Design-Time Support to Your Extender Control 525

Figure 11.4 Extender properties on the image control

Page 26: Download the sample pages.pdf

Adding Designers and Editors to PropertiesIn this section, we look at how to extend the design-time behavior of ourImageRotator ImageList property. The ImageList property that weworked with in Chapter 5 was rudimentary and prone to errors as a userentered in the values. In this version of the extender, we want to extend thefunctionality to support design-time editing and HTML source editing.

The road to these modifications requires a few steps as we add the functionality:

1. Add attributes to the class.

2. Add attributes to the property.

3. Add editors to assist in assigning values.

4. Create a type converter to support serialization.

Add Attributes to the Class

Most users expect when adding multiple entries to a control to be able toadd them in the body of the HTML element. This is the experience we have when adding web service references or script references to the ScriptManager and one we want to have in our control.

The ParseChildren attribute enables us to add multiple entries insideour ImageRotator HTML tag and treat those entries as a single propertyassignment. By setting the ChildrenAsProperties property to true and theDefaultProperty to ImageList, as in Listing 11.6, we are effectively tellingthe designer that we want to have all the items contained in the body of ourImageRotator tag parsed and assigned to the ImageList property. TheHTML fragment in Listing 11.7 shows what this looks like when the HTMLeditor is opened and the ImageRotator tag has entries.

Listing 11.6 ParseChildren Attribute Assignment

[ParseChildren(true, "ImageList")]...public class ImageRotatorExtender : ExtenderControlBase{

...}

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

526

Page 27: Download the sample pages.pdf

Listing 11.7 ImageList Assignment in HTML

...<asp:Image ID="BannerImage" runat="server" ImageUrl="~/images/1.jpg" /><cc2:ImageRotatorExtender ID="BannerImage_ImageRotatorExtender"runat="server" Enabled="True" TargetControlID="BannerImage"><cc2:ImageUrl Url="~/images/2.jpg" /><cc2:ImageUrl Url="~/images/3.jpg" /><cc2:ImageUrl Url="~/images/4.jpg" />

</cc2:ImageRotatorExtender>...

Adding Design-Time Support to Your Extender Control 527

NOTE ASP.NET Server Control Designer References

The addition of designer features to your extenders requires some knowledge of how designers work. MSDN has some greatinformation about this at http://msdn2.microsoft.com/en-us/library/aa719973%28VS.71%29.aspx that covers adding design-timesupport to ASP.NET server controls.

Add Attributes to the Property

To fully implement the ability to add nested image entries to our ImageRotator extender, we need to add a couple of attributes, as shown in List-ing 11.8, to our ImageList property, which provides hooks for the designerto integrate with our property and properly assign the image values.

The DesignerSerializationVisibility attribute is added to the prop-erty to ensure that the designer will serialize the contents of the propertyduring design time. The setting of DesignerSerializationVisibility.Content instructs the designer to generate code for the contents of the tagand not the tag itself.

The PersistenceMode attribute is the other piece to this puzzle and isresponsible for adding the <ImageUrl .. /> entries inside our ImageRotatortag as we add values to the property in the Properties window. The setting ofPersistenceMode.InnerProperty specifies that the property is persisted asa nested tag inside the ImageRotator, as shown in Listing 11.7.

Page 28: Download the sample pages.pdf

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

528

Listing 11.8 Designer-Specific Attributes for the ImageRotatorExtender Class

[ParseChildren(true, "ImageList")]...public class ImageRotatorExtender : ExtenderControlBase{...

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

[PersistenceMode(PersistenceMode.InnerDefaultProperty)]public ImageUrlList ImageList{...

}}

Add Editors to Assist in Assigning Values

The use of editors in your extenders can greatly enhance the user experi-ence during design time and in some cases can lead to more accurate entryof data. Recall from Chapter 5 that we entered images to the ImageListproperty by adding URL entries and separating them using commas. Thisrudimentary approach would not be expected by a consumer of a profes-sional control. In this version of the ImageRotator, we want to enhance thedata entry of the images by providing an editor that can be used to addimage URL entries and have those entries placed into the body of ourImageRotator HTML tag. If we go back to the ScriptManager control, thisis the experience it provides when adding web service or script referenceswhile in the Properties window.

The ImageList property in this version of the ImageRotator uses twoeditors to provide a rich design-time experience when adding ImageUrlentries. The first editor is a Collection editor, shown in Figure 11.5, and isdesigned to assist in adding, editing, and removing values that are based ona Collection. The editor is automatically associated with our ImageListproperty because the type of the property is a Collection. The second edi-tor we will use is the ImageUrlEditor, shown in Figure 11.6, which theImageUrl entry uses to assist the user in entering a URL. This editor is asso-ciated with the Url property of the ImageUrl class, as shown in Listing 11.9,by adding the Editor attribute to the property. We use the Editor attribute

Page 29: Download the sample pages.pdf

to configure which editor to use when adding values to the property in thedesigner. In our case, we are using the ImageUrlEditor to provide the userwith a clean way to find an image located in a web application and assignthe value to the ImageUrl property. The use of the associated UrlPropertyattribute provides a filter that identifies specific file types that can be usedto filter against the ImageUrl property.

Adding Design-Time Support to Your Extender Control 529

Figure 11.5 Image URL Collection Editor

Listing 11.9 ImageUrl Class

[Serializable]public class ImageUrl{[DefaultValue(""),Bindable(true), Editor("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)),UrlProperty]

public string Url { get; set; }}

Page 30: Download the sample pages.pdf

Figure 11.6 Image URL Editor

Create a Type Converter to Support Serialization

The use of complex types presents a few challenges in the ASP.NET AJAXControl Toolkit during the script generation process. The problem arises inhow the ASP.NET AJAX Control Toolkit serializes your extender controlproperties as it creates the $create statement. By default, the toolkit triesto get the default string representation of the value your property repre-sents. In most cases, this is an easy task because most simple types convertto a string relatively easily. If you are using complex types, however, thiscan present a problem because the default ConvertToString() representa-tion of a complex object is its type name. To resolve this issue, you must cre-ate a type converter and associate it with the complex type. When theASP.NET AJAX Control Toolkit encounters a type during script generation,it looks to see whether the type has a converter. If it does, it uses the con-verter to convert the data instead of using the default ConvertToString()method. In this section, we walk through creating a System.ComponentModel.TypeConverter that will be used to convert our ImageUrlList type

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

530

Page 31: Download the sample pages.pdf

into a JavaScript Object Notation (JSON) string that can be consumed onthe client.

The ImageListConverter, shown in Listing 11.10, is designed to convertthe ImageList to a JSON array of image URLs that are then passed back tothe client. The creation of this type converter now enables us to return adata format that the client can use instead of a string that contains the typename of the ImageList. For the type converter to be used, we need to asso-ciate it with the ImageList type. We do this by adding the TypeConverterattribute to the ImageList class, as shown in Listing 11.11, and assigning thetype of the ImageList to it. Now when the toolkit performs a ConvertToString on the ImageList, the JSON string representation of the ImageList will be returned.

Adding Design-Time Support to Your Extender Control 531

NOTE Use of the DataContractJsonSerializer

In more complex situations, you might use the DataContractJsonSerializer that we discussed in Chapter 8, “ASP.NET AJAX Communication Architecture,” which replaces theSystem.Web.UI.JavaScriptSerializer class as the new JSON serializer to convert yourdata to JSON format.

Listing 11.10 ImageListConverter Type Converter Class

public class ImageListConverter : TypeConverter{public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)

{Collection<ImageUrl> imageList = value as Collection<ImageUrl>;if (imageList != null && destinationType == typeof(string)){StringBuilder builder = new StringBuilder();builder.Append("[");bool first = true;foreach (ImageUrl imageUrl in imageList){if(first){first = false;

}else

Page 32: Download the sample pages.pdf

Listing 11.10 continued

{builder.Append(",");

}

builder.Append("\"");builder.Append(imageUrl.Url.Replace("~/", ""));builder.Append("\"");

}builder.Append("]");return builder.ToString();

}return base.ConvertTo(context, culture, value, destinationType);

}}

Listing 11.11 ImageUrlList Collection Class

[Serializable][TypeConverter(typeof(ImageListConverter))]public class ImageUrlList : Collection<ImageUrl>{

}

Adding Animations to Your Extender Control

The ASP.NET AJAX Control Toolkit comes with a rich animation frame-work that provides support for creating cool visual effects on your pages.The animation framework consists of a set of JavaScript and .NET classesthat enable you to build up animations of all types, including animationsthat run sequentially or in parallel, animations that fade the opacity of acontrol in and out, and animations that transition from one color to thenext. The framework provides support for building these animations usingthe JavaScript API directly or using a declarative approach that consists ofadding markup in the HTML editor. The following sections examine howto add animation functionality to extender controls.

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

532

Page 33: Download the sample pages.pdf

Animations Using the JavaScript APIThe ImageRotator extender we created earlier provided little in the area ofeffects as the images switched and resulted in very fast transition from oneimage to the next, which wouldn’t catch a viewer’s attention. In this sec-tion, we create a new version of the ImageRotator, called the AnimatedImageRotator, that fades in the image as it switches from one image to thenext and provides this feature in addition to the existing functionality of theImageRotator. As we cover how to add this new animation functionality,we gloss over the topics we have already covered, focusing only on imple-menting the animation pieces.

To add this functionality to the AnimatedImageRotator, we need to reg-ister the animation scripts with the AnimatedImageRotatorExtender classand add logic to the behavior class to call the animation when the imagechanges.

Registering the Animation Scripts

To register the script files so that they are downloaded to the browser, weneed to add the RequiredScript attribute to the AnimatedImageRotatorExtender class, as shown in Listing 11.12. We use the RequiredScriptattribute in this case to ensure that the animation.js, timer.js, and common.jsscript files associated with the AnimationScripts type are included withthe scripts brought down to the browser for our control. This style ofadding scripts associated with a type is a common practice in the toolkitand is clean way to include dependent scripts associated with a type.

Listing 11.12 AnimatedImageRotator Extender Class

...[RequiredScript(typeof(AnimationScripts))]...public class AnimatedImageRotatorExtender : ExtenderControlBase{...

}

Adding Animations to Your Extender Control 533

Page 34: Download the sample pages.pdf

Calling Animation APIs

The ASP.NET AJAX Control Toolkit contains a JavaScript API that you canuse to provide animation support on the client. In the case of our AnimatedImageRotator extender, we will use the FadeAnimation, which is part of theanimation API, to provide a fade-in effect when the images on our imagecontrol change. The JavaScript code to implement this functionality will becontained in our behavior class and will integrate with the existing featuresof the ImageRotator.

The AnimatedImageRotator behavior class, shown in Listing 11.13, takesthe ImageRotator behavior and adds a fade animation when the imagechanges, to fade the image into view. The constructor of the FadeAnimationtakes the target of the animation, the duration of the animation, the numberof steps per second, the effect, the minimum opacity, the maximum opacity,and whether to adjust for layout in Internet Explorer. In our case, the BannerImage image control will be the target of our animation, and theduration of our animation will be hard coded to 20% of the time the imageis visible. To provide a clean animation, we will set the animation steps to150, and combine that with a fade-in effect that will cause the image to tran-sition in when the image changes. During this transition, we will start offwith an opacity of 0, which will give us a full view of the image back-ground, and then through the 150 steps work our way to a full view of theimage with an opacity of 1. Table 11.1 lists some of the FadeAnimation prop-erties and provides a little more information about what they do.

After we associate the animation to the element, starting, stopping, andpausing the animation is just a method call away, making it simple tomanipulate the animation. In the AnimatedImageRotator, the load event ofthe image is used to trigger the animation to play because it will be firedeach time our Sys.Timer calls the _rotateImage method. To do this, weassociated the _onLoadImage event handler with the onLoad event of theimage and called the play method on the animation inside the function.Now each time the load event occurs, the animation plays, transitioning theimage into view. One of the side effects of working with an animation in asituation like this is a potential race condition if the duration was set toolong. When working with transition-type animations like the FadAnimation,pay close attention to how you are using it to ensure the animation will workin all cases.

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

534

Page 35: Download the sample pages.pdf

Listing 11.13 AnimatedImageRotator Behavior Class

...

AnimatedImageRotator.AnimatedImageRotatorBehavior = function(element) {...this._fadeAnimation = null;this._timer = null;this._onImageLoadHandler = null;

}AnimatedImageRotator.AnimatedImageRotatorBehavior.prototype = {initialize : function() {...

if(this._fadeAnimation == null){this._fadeAnimation = new AjaxControlToolkit.Animation.FadeAnimation(element, this._rotationInterval/20, 150,AjaxControlToolkit.Animation.FadeEffect.FadeIn, 0, 1, true);

}if (element) {this._onImageLoadHandler = Function.createDelegate(this,this._onImageLoad);

$addHandler(element, 'load', this._onImageLoadHandler);}...

},

dispose : function() {...var element = this.get_element();if (element) {if (this._onImageLoadHandler) {$removeHandler(element, 'load',this._onImageLoadHandler);

this._onImageLoadHandler = null;}

}

...

if (this._fadeAnimation){this._fadeAnimation.dispose();this._fadeAnimation = null;

}

...

Adding Animations to Your Extender Control 535

Page 36: Download the sample pages.pdf

Listing 11.13 continued

},_onImageLoad: function(){if(this._fadeAnimation)this._fadeAnimation.play();

},...

}...

Table 11.1 Partial List of Fade Animation Class Properties

Property Description

target Target of the animation.

duration Length of the animation in seconds. The default is 1.

fps Number of steps per second. The default is 25.

effect Determine whether to fade the element in or fade the ele-ment out. The possible values are AjaxControlToolkit.Animation.FadeEffect.FadeIn and AjaxControlToolkit.Animation.FadeEffect.FadeOut. The default value isFadeOut.

minimumOpacity Minimum opacity to use when fading in or out. Its valuecan range from 0 to 1. The default value is 0.

maximumOpacity Maximum opacity to use when fading in or out. Its valuecan range from 0 to 1. The default value is 1.

forceLayoutInIE Whether we should force a layout to be created for InternetExplorer by giving it a width and setting its backgroundcolor (the latter is required in case the user has ClearTypeenabled). The default value is true.

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

536

Page 37: Download the sample pages.pdf

Animations Using the Declarative MethodThe declarative approach to animation in the toolkit provides a nice exten-sibility path for consumers of your extender. In our previous example, wehard coded all the animation functionality inside our extender, providinglittle support for developer customization. In some cases, this might be allthat is needed. In other cases, however, you might need to provide a morerobust solution that provides a JavaScript-free way to customize anima-tions. In this section, we replicate the same functionality we created in thepreceding section, but we provide a more extensible approach consumersof our extender can use when they are configuring it in the designer. Theextender we create has just one feature: the capability to run a FadeIn ani-mation when the onLoad event of an associated image control occurs. Thisnew extender will be used in addition to the ImageRotator extender we cre-ated earlier, which had no animation functionality. This refined approach toadding animation support builds on the principle that many extenders canbe placed on a single control to provide combined client-side capabilities.To get started, let’s take a look at what the declarative syntax or our con-trol will look like before we go into the implementation details. Just as inthe preceding section, as we cover how to add this new animation func-tionality we gloss over the topics we have already covered, focusing onlyon implementing the declarative animation pieces.

Overview of Declarative Syntax

To get started, let’s look at the HTML source we will be working towardbeing able to work with in our ImageAnimation extender. The source in List-ing 11.14 contains an ImageAnimationExtender tag that contains in its bodyan Animations tag. As you might guess, the approach here is to add variousanimations that are driven by events raised by the image control we areextending. In our case, we are working with the OnLoad event and addinga Sequence animation that will call a child Fade animation. A Sequence ani-mation is designed to run all its child animations one at a time until all havefinished. So, what this source tells us is that our extender will have an ani-mation that will be tied to the OnLoad event of the image control and willrun the child Fade animation whenever the OnLoad event occurs.

Adding Animations to Your Extender Control 537

Page 38: Download the sample pages.pdf

Listing 11.14 AnimationImageExtender Declarative Syntax

<asp:Image ID="BannerImage" runat="server" ImageUrl="~/images/1.jpg" /><cc3:ImageAnimationExtender ID="Banner_ImageAnimationExtender" runat="server" Enabled="True" TargetControlID="BannerImage"><Animations><OnLoad><Sequence><FadeIn AnimationTarget="BannerImage" Duration=".3"/>

</Sequence></OnLoad>

</Animations></cc3:ImageAnimationExtender><cc2:ImageRotatorExtender ID="Image1_ImageRotatorExtender" runat="server" Enabled="True" TargetControlID="Banner"><cc2:ImageUrl Url="~/images/2.jpg" /><cc2:ImageUrl Url="~/images/3.jpg" /><cc2:ImageUrl Url="~/images/4.jpg" />

</cc2:ImageRotatorExtender>

Providing Declarative Support in Your Extender Class

The AnimationExtenderControlBase class provides most of the function-ality we need to parse the Animation tag and all its contents. This class pro-vides internal methods that convert the XML representation of theanimation into JSON format, which our behavior will then use to run theanimation, and also provides the Animation property that we see in List-ing 11.15. The following sections cover the steps needed to ensure the exten-der will work correctly.

1. Add attributes to the class.

2. Create a property for the event.

3. Add attributes to the property.

Add Attributes to the Class

This type of extender has a couple of added class attribute entries of inter-est to us. The first is the inclusion of the RequiredScript attribute for theAnimationExtender type. The AnimationExtender class provides a lot ofthe client-side functionality we will be using in our extender control, and byusing this type in our RequiredScripts attribute, we are guaranteed that

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

538

Page 39: Download the sample pages.pdf

the scripts will be present on the client for us to use. The second attributeis the System.Web.UI.Design.ToolboxItem attribute, which enables ourcontrol to show up in the toolbox of Visual Studio. It might seem strangethat we have to add this because all our other extenders didn’t. If we lookat the attributes on the AnimationExtenderControlBase class, however, thesupport for viewing in the toolbox has been turned off. Therefore, we mustreset this value on our control so that it will show up in the toolbox.

Create a Property for the Event

The pattern when creating extenders of this type is to add a property foreach event you want to interact with. In our case, we are working with theOnLoad event, so we create a property named OnLoad (to make it easy tounderstand what the event is). If we were to choose other events, we wouldname them based on the DOM event they represent. The property accessorfor these events must use the GetAnimation and SetAnimation methods toensure proper data conversion into JSON as the data is stored and retrievedout of the extender’s view state.

Add Attributes to the Event Property

The event property must have the Browsable, DefaultValue, Extender

ControlProperty, and DesignerSerializationVisibility attributesapplied to it. The Browsable attribute stops the property from showing up inthe Properties window and therefore excludes the property from beingassigned in the Properties window. This is needed because no editor is asso-ciated with this property, and we don’t want users to try to add anything intothe Properties window that would corrupt the values. The DesignerSerializationVisibility attribute with a value of DesignerSerializationVisibility.Hidden is used to indicate that the property value should not bepersisted by the designer because the Animation property will take care ofthat for us. The DefaultValue attribute indicates to the designer that thedefault value will be null, and the ExtenderControlProperty attribute isused to register the property with the ScriptComponentDescriptor.

Adding Animations to Your Extender Control 539

Page 40: Download the sample pages.pdf

Listing 11.15 ImageAnimationExtender Class

[Designer(typeof(ImageAnimationDesigner))][ClientScriptResource("ImageAnimation.ImageAnimationBehavior", "ImageAnimation.ImageAnimationBehavior.js")]

[RequiredScript(typeof(AnimationExtender))][ToolboxItem("System.Web.UI.Design.WebControlToolboxItem, System.Design,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")][TargetControlType(typeof(Image))]public class ImageAnimationExtender : AnimationExtenderControlBase{private Animation _onLoad;

[DefaultValue(null)][Browsable(false)][ExtenderControlProperty][DesignerSerializationVisibility(

DesignerSerializationVisibility.Hidden)]public new Animation OnLoad{get { return GetAnimation(ref _onLoad, "OnLoad"); }set { SetAnimation(ref _onLoad, "OnLoad", value); }

}}

Adding Declarative Support to Your Behavior Class

The ImageAnimationBehavior class, shown Listing 11.16, provides all theclient-side functionality for our extender with support from the animationscript files associated with the AutomationExtender class. These associatedscripts provide support for converting the JSON representation of theFadeIn animation that was captured on the server to an actual animation,support for associating the animation with the high-level OnLoad event, andsupport for playing the animation when the OnLoad event occurs.

You need to complete a few steps for each event you plan to work with:

1. Add variables to the class.

2. Create functions.

3. Add handlers.

Add Variables to the Class

Each event that your behavior will work with needs a variable that refer-ences the GenericAnimationBehavior for the event and a delegate that will

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

540

Page 41: Download the sample pages.pdf

be called for the event that will be processed. In the ImageAnimationBehavior class, we use the _onLoad variable to store a reference to theGenericAnimationBehavior class and the _onLoadHandler variable to storea reference to the delegate that will handle the onLoad event. The guidelinesestablished so far in the toolkit use a naming convention that includes theevent name in all the variable names.

Create Functions

The behavior needs a series of functions for each event you will work with.The get_OnLoad and set_OnLoad functions in our case take care of workingwith the JSON-based data for the FadeIn animation and utilize the func-tionality provided by the GenericAnimationBehavior class to store andretrieve that data. The get_OnLoadBehavior function returns a reference tothe GenericAnimationBehavior instance that was created for our FadeInanimation, providing the ability to work with the behavior that directlyexposes the play, stop, and quit methods common to all animations.

Add Handlers

Handlers must be added for each event the behavior will process andshould correspond to the events exposed on the extender control. In ourcase, we are working with the onLoad event, so we need to create the_onLoadHandler delegate and associate it with the onLoad event of theimage using the $addHandler shortcut. The opposite of this must happen inthe dispose of our behavior, when we use the $removeHandler shortcut toensure proper memory cleanup.

Listing 11.16 ImageAnimationBehavior Class

Type.registerNamespace('ImageAnimation');

ImageAnimation.ImageAnimationBehavior = function(element) {ImageAnimation.ImageAnimationBehavior.initializeBase(this, [element]);this._onLoad = null;this._onLoadHandler = null;

}ImageAnimation.ImageAnimationBehavior.prototype = {initialize : function() {ImageAnimation.ImageAnimationBehavior.callBaseMethod(this, initialize');

var element = this.get_element();

Adding Animations to Your Extender Control 541

Page 42: Download the sample pages.pdf

Listing 11.16 continued

if (element) {this._onLoadHandler = Function.createDelegate(this, this.OnLoad);$addHandler(element, 'load', this._onLoadHandler);

}},

dispose : function() {ImageAnimation.ImageAnimationBehavior.callBaseMethod(this, 'dispose');

var element = this.get_element();if (element) {if (this._onLoadHandler) {$removeHandler(element, 'load', this._onLoadHandler);this._onLoadHandler = null;

}}

this._onLoad = null;

},get_OnLoad : function() {return this._onLoad ? this._onLoad.get_json() : null;

},set_OnLoad : function(value) {if (!this._onLoad) {this._onLoad = new AjaxControlToolkit.Animation.GenericAnimationBehavior(this.get_element());

this._onLoad.initialize();}this._onLoad.set_json(value);this.raisePropertyChanged('OnLoad');

},get_OnLoadBehavior : function() {return this._onLoad;

},OnLoad : function() {if (this._onLoad) {this._onLoad.play();

}}

}ImageAnimation.ImageAnimationBehavior.registerClass('ImageAnimation.ImageAnimationBehavior', AjaxControlToolkit.BehaviorBase);

Chapter 11: Adding Client Capabilities to Ser ver ControlsUsing the ASP.NET AJA X Control Toolkit

542

Page 43: Download the sample pages.pdf

Final Thoughts

The HTML source for our sample, shown Listing 11.14, contains a Fade ani-mation that targets the BannerImage control and runs for a duration of .3 seconds. We could have chosen almost any type of animation as long asit occurred when the OnLoad event fired on the BannerImage image control.This flexibility provides a JavaScript-free way to set up animations of anytype when a pattern such as this is used. In fact, this is exactly how the Animation extender works; and if it weren’t for the way it handles theOnLoad event, we would have used it in our example.

SUMMARY

The AJAX Control Toolkit comes with quite a bit of functionality that youcan use to create truly interactive extenders that require much less codingthan if you were to use the ASP.NET 2.0 AJAX Extensions directly. As youlearned in this chapter, the toolkit provides a much richer environment forcreating extender controls than using the ASP.NET 2.0 AJAX Extensionsalone. In addition, the toolkit includes myriad controls you can either useor build on, making the toolkit a compelling alternative.

Summary 543

Page 44: Download the sample pages.pdf

Index

Symbols_ (underscore), 64_component object, adding

components to, 177_doInitialize method, 189_format method, 301_onBlur method, 302_onFocus method, 302_validateParams function, 557__cultureInfo variable, 292$create statements, 243$find method, 180

Aabstract data types, 40-45Accept-Language headers, 262accessingbase class methods, 80enumerations, 73folders, 440private members, 81properties, 47raw events, 112roles, 440

AcquireRequestState event, 566actions, animations, 508-509ActiveX Template Library (ATL), 524add_init method, 195, 364

Add User screen, 437AddAttributesToRender method, 343addComponent method, 177AddComponentProperty

method, 211AddElementProperty method, 211addinganimations to extender controls,

532-543attributes, 538AutoComplete page methods, 498behavior, ExtenderControl class,

220-233client-side behavior,

ExtenderControlBase, 513-523client-side functionality, 247-254components, 177-178controls, 246custom events, 90design-time support to extender

controls, 524-532designers to properties, 526-532editors to properties, 526-532error publishing feature, 133filters, 308-310functionality, ScriptControl class,

233-246handlers, 130, 541

577

Page 45: Download the sample pages.pdf

multiple handlers, 91propertiesExpando, 75instances, 40

references, 526script resources, 215users, 437variables, 540

addresses, URIs, 380AddScriptProperty method, 212administrationcomponents, 123roles, 439-441Web Site Administration Tool,

431-432, 437AJAX-enabled WCF services, 382AjaxControlExtender.vsi file, 484AjaxControlToolkit.BehaviorBase

class, creating, 521-522alertserror messages, 302timeouts, 32

Allow element, 429amountsfilters, defining, 308localization, 267

AnimatedImageRotator class, 534AnimatedImageRotatorExtender

class, 533Animation class, 485, 503AnimationExtenderControlBase

class, 511, 539animationsextender controls, adding to, 532-543support for, 483Toolkit (ASP.NET AJAX Control),

501-503client architecture, 503-508server architecture, 509-512

anonymous functions, generating, 34

APIs (application programminginterfaces), 375

JavaScript, 533-536membership login, 436roles, 443

ApplicationManager, 559applicationsASP.NET 2.0, 425-433. See also

ASP.NET 2.0ASP.NET AJAX application

services, 448authentication, 448-452profiles, 456-459roles, 453-454

HTTPhandlers, 560-565modules, 565-568

lifecycles, 394-395, 559-560localization, 255-256determining what needs to be

localized, 257-261displayed values, 267-276running under particular cultures,

261-266services, 460-466, 469-478Sys.Application class. See

Sys.Application classweb, xxvii, 398-400Web Site Administration Tool,

431-432, 437applyingauthentication services, 450event parameters, 145-148getBaseType, 84inheritsFrom types, 83instanceOfType, 84interfaces, 86-88intervals, 38IScriptControl interfaces, 247-254KnownType attributes, 392

Index578

Page 46: Download the sample pages.pdf

Index 579

load events, 200pageload method, 201profile services, 457property parameters, 140-145references parameters, 149-150role services, 454scripts, 219type parameters, 136-139WebResource attribute, 216

architectureASP.NET 2.0 AJAX Extensions, 374page methods, 386-387serialization, 388-394server framework components,

394-400web services, 375-386

ASP.NET AJAX Control Toolkit, 481animations, 501-512client-based, 499-501composition of, 483-486overview of, 482-483server-based, 486-487, 491-499

Microsoft AJAX Librarycommunication architecture, 401

serialization, 415-416service proxies, 401-415WebRequest class, 417-424

new communication paradigm, 372-373

script-based, 208behavior and control, 208-218resources, 214-219

argumentsdynamic, 22explicit, 22implicit, 21JavaScript, 16-25undefined, 22

arraysassociative, comparing objects, 10extending, 55-59

ASP.NETapplication lifecycles, 394-395services, registering, 385

ASP.NET 2.0AJAX Extensions, xxx, 374page methods, 386-387serialization, 388-394server framework components,

394-400web services, 375-386

membership, role, and user profileservices, 425-436

Provider Model, 429-431ASP.NET AJAX, 448authentication, 448-452localization in, 277-280profiles, 456-459roles, 453-454

ASP.NET AJAX Control Toolkit, xxxarchitecture, 481animations, 501-512client-based, 499-501composition of, 483-486overview of, 482-483server-based, 486-499

extender controls, creating, 220AspNetCompatabilityRequirements

attribute, 382assemblies, 476-477assigningnull, 12properties, 243references, 149

associative arrays, 10ATL (ActiveX Template Library), 524attachingevent handlers, 107extenders to controls, 231-233, 523Sys.UI.DomEvent, 110

Page 47: Download the sample pages.pdf

attributesadding, 538AspNetCompatabilityRequirements,

382ClientCssResource, 491code with, 488code without, 487DataContract, 379development, simplification of, 482ExtenderControlEvent, 489ExtenderControlProperty, 489JavaScript, 4-6primitive data types, 6objects, 9-15

KnownType, 392, 412-413OperationContract, 407param element, 553ParseChildren, 526RequiredProperty, 489ScriptResource, 305server-based architecture, 486-491UrlProperty, 241WebResource, 216

AuthenticateRequest event, 566authenticationforms, 426-429services, 448-452

authorization element, configuring,428-429

AuthorizeRequest event, 566AutoComplete page method,

adding, 498AutoCompleteDesigner class, 499automatic disposalof behaviors and controls, 329-337of components, 337-339, 351-355

AutomationExtender class, 540

Bbackslash (\), 8backspace character, 8base class methodsaccessing, 80calling, 82ErrorHandler components, 132-133overriding, 81redefining, 48server-based architecture, 491-494

beginCreateComponentsmethod, 189

BeginRequest event, 566beginUpdate method, 129BehaviorBase class, 500, 521behaviors, 159-161, 380client-side, 513-523components, 122-124creating, 162-167defining, 161-162ExtenderControl class, adding,

220-233partial postbacks, 324-328automatic disposal, 329-339manual disposal, 340-355

script-based architecture, 208-218UpdatePanel, 318-324

bindings, 380blocks, finally, 28booleans, 6, 52bubbleSort method, 68defining, 70testing, 71

bubbling, event, 154bugs, parseLocale method, 284-285built-in types, extending, 52arrays, 55-59booleans, 52dates and numbers, 53strings, 54-55

Index580

Page 48: Download the sample pages.pdf

Index 581

CC# base class methods, calling, 82caching scripts, 306call stacks, 190callbacks, 115-116callee property, 24caller property, 24callinganimation scripts, 534-536base class methods, 82

canceling timeouts, 30capabilitieslocalization, 280-281script globalization, 281-291

capitalization, constructors, 63carriage return characters, 8categories of JavaScript, 4central locations, managing

components, 176characters, special, 8checkAmounts function, 310checking function parameters, 555classesAjaxControlToolkit.BehaviorBase,

521-522AnimatedImageRotator, 534AnimatedImageRotatorExtender, 533Animation, 503AnimationExtenderControlBase,

511, 539attributes, adding, 538AutoCompleteDesigner, 499AutomationExtender, 540BehaviorBase, 500, 521ControlBase, 501designer, 495, 498-499ErrorEventArgs Client, 571ErrorHandler Client, 569-575ExtenderControl, 220-233

ExtenderControlBase, 492-494attaching extenders to controls, 523creating AjaxControlToolkit.

BehaviorBase class, 521-522inheriting from, 518-520

ExtenderControlBaseDesigner{T},497-499, 517

GenericAnimationBehavior, 541Image URL, 530JavaScript, 483Microsoft AJAX Library, 60-67MyHandlerFactory, 563.NET, 483ProfileBase, 445prototype serialization, 416proxy services, 473-477registering, 79ScriptBehaviorDescriptor, 213ScriptComponentDescriptor,

210-213, 488-489ScriptControl, 233-246ScriptControlBase, 495ScriptControlDescriptor, 208, 214ScriptControls, 491-494ScriptManager, 218-219ScriptReference, 216SearchCriteria, 381Service1, 377ServiceReference, 385SimpleWCFService, 473StackTrace Client, 572-573Sys.Application, 169. See also

Sys.Application classSys.Component, 125, 129creating components, 134-151defining new components, 129-134

Sys.EventArgs, 93Sys.Net.WebProxy, 449, 456Sys.Net.WebRequestManager, 422Sys.Net.XMLHttpExecutor, 422

Page 49: Download the sample pages.pdf

Sys.Services.AuthenticationService,449

Sys.Services.ProfileService, 456Sys.Services.RoleService, 453Sys.UI.Behavior, 122, 208-218creating, 229-230methods, 159template, 225

Sys.UI.Control, 122, 152, 208-218SysCultureInfo, 290-293TextBoxInfo, 244-246Transactions, 260-261UserProfile, 445WCFHandler, 465WebControl, 234WebRequest, 417-424WebServiceError, 403WebServiceProxy, 415

clearing intervals, 38, 336clickEventHandler method, 114-116client-based architecture, 499BehaviorBase class, 500ControlBase class, 501

client-side behavioradding, 513-523ExtenderControl class, 220-233functionalityExtenderControl class, 233-246IScriptControl interface, 247-254

client-side JavaScript. See CSJSClientCssResource attribute, 491ClientPropertyName attribute, 489clientsapplication lifecycles, 559-560components. See componentscontrols, HoverCard, 343ErrorHandler code, 569-575libraries, IntelliSense, 549login, 451Sys.Application class, 169creating, 170-172

initialization routines, 185-198load events, 198-203managing components, 177-185method information, 172-175type information, 172unload routines, 203-206

closures, 45codedelayed code execution, 30-38Errorhandler client, 569-575with/without attributes, 487-488

comments, XML, 551-554Common folder, 485communicationarchitecture, 372. See also architectureWCF, 375-386

CommunicationSupportnamespace, 466

comparing null and undefinedvalues, 18

complex data and serialization, 391components, xxixadding, 177-178ASP.NET 2.0 AJAX Extensions, xxxASP.NET AJAX Control Toolkit, xxxbehaviors, 122-124, 159-161creating, 162-167defining, 161-162

controls, 122-124, 151-154creating, 157-159defining, 155-157

creating, 189-191, 193-198defining, 178definition of, 121-122deleting, 183-184ErrorHandler, 129-134, 351-355Microsoft AJAX Library, xxixpartial postbacks, 324-328automatic disposal, 329-339manual disposal, 340-355

retrieving, 184-185

Index582

Page 50: Download the sample pages.pdf

Index 583

searching, 179-183server frameworks, 394-400Sys.Application class, 169creating, 170-172initialization routines, 185-198load events, 198-203managing, 177-185method information, 172-175type information, 172unload routines, 203-206

Sys.Component class, 125, 129creating, 134-151defining new components, 129-134

composite controls, 247-254concatenation, strings, 9configuringAjaxControlToolkit.BehaviorBase

class, 521-522ASP.NETapplication services, 449web applications, 398-400

authorization element, 428-429behaviors, 159-167components, 134-151, 189-198skeletons, 129-130

composite controls, 250controls, 157-159creating script controls, 237-246

current cultures, 262-266data contracts, 383-384dataContractSerializer element, 393error types, 58Forms authentication, 427functions, 5handlers, 541HTTP handlers, 477ImageRotator extenders, 514-517inheritance, 79-84instances with parameters, 42internal controls, 250namespaces, 61

objects, 9profiles, 447services, 456-459

references, 196-198rolesaccessing, 440services, 453

ScriptManager control, 218-219servicescontracts, 381-383registering, 384-385

Sys.Application, 170-172Sys.UI.Behavior class, 229-230type converters, 530-532web applications, 398-400

consoles, Sys.Debug, 98constructorscapitalization, 63DataContractJsonSerializer, 390parameters, 41, 63properties, 15ScriptControlDescriptor class, 214ScriptReference class, 217Sys.Application, 170-171

containersanimations, 504-505naming, 249

contractsdata, creating, 383-384services, creating, 381-383types of, 376data, 378-379service, 376-378

ControlBase class, 501controls, 151-154adding, 246components, 122-124composite, adding functionality,

247-254creating, 157-159CurrencyTextBox.cs, 297

Page 51: Download the sample pages.pdf

defining, 155-157ExtenderControl class, 220-233ExtenderControlBase, 513-523extendersanimations, 532-543attaching, 231-233design-time support, 524-532

GridView transactions, 259internalcreating, 250rendering, 251

membership, 435partial postbacks, 324-328automatic disposal, 329-339manual disposal, 340-355

ScriptManagerProxy, 218-219scriptsarchitecture, 208-218creating, 237-246

servers, xxvii, xxxiiiErrorHandler, 571-572HoverCard, 341-351

SimpleComponent, 327state, 493TextBoxInfo, 240UpdatePanel behavior, 318-324WebControl class, 234

conversion, implicit, 14converters, creating type, 530-532CSJS (client-side JavaScript), 4Culture Selector drop-down, 271cultures. See also localizationInvariant, 286resource files, 273-276

CurrencyTextBox, 295-312current cultures, configuring, 262-266curry methods, 36customizingapplication services, 460-478asynchronous executors,

creating, 417events, adding, 90Sys.EventArgs class, 93

Ddata contracts, 378-379, 383-384data format strings, 289data typesabstract, 40-45primitive, 6wrapper objects, 14

DataContractJsonSerializer, 389, 416constructors, 390methods, 391

DataContractSerializer element, 393datesextending, 53JavaScript, 279-280localization, 267script globalization, 286-287

debuggingmessages, 325_validateParams function, 556

declarative animations, 509-512, 537-543

declaringnamespaces, 61-62page methods, 387public interfaces, 65-66string variables, 8types, 62-65

default design-time, extendercontrols, 525

default resource files, 271default ScriptManager control

behavior, 218default values, private members, 41definingamounts, filtering, 308behaviors, 161-162bubblesSort method, 70components, 129-134, 178constructors with parameters, 63controls, 155-157enumerations, 73error types, 58Filter.Res objects, 312

Index584

Page 52: Download the sample pages.pdf

Index 585

formattable objects, 289initializeBaseType function, 46interfaces, 68private members, 300properties, 300protocol-based methods, 43pubic members, 42TestType, 83types, 40-41, 63

delayed code execution, 30-38delegates, 113, 147deletingcomponents, 183-184multiple handlers, 91Sys.UI.DomEvent, 110

Deny element, 429descriptorsevent names in, 212property names used in, 210

deserialize method, 416design, adding extender controls,

524-532designer classesserver-based architectureToolkit (ASP.NET AJAX Control),

495-499designersproperties, adding to, 526-532references, 527

developmentsimplification of, 482UpdatePanel, behavior, 318-324

dictionaries, passing in, 116disabling error publishing

features, 133displayed values, localizing, 267-276dispose method, 130, 300dispose scripts, 337-339div tags, wrapping HoverCards

in, 346

DOM (Document Object Model)behaviors, 159-161creating, 162-167defining, 161-162

controls, 151-154creating, 157-159defining, 155-157

elements, 9, 557modifying, 192

double quote (“), 8downloading Ajax Control

Toolkits, 484DragPanelExtender, 347duplicate functionality, 495duration property, 536dynamic arguments, 22dynamically typed languages, 4-5

EECMAScript standard, 4Edit User screen, 437editing users, 438editorAdded event, 93editorAddedHandler method, 92editorsImageURL, 242properties, adding to, 526-532

effect property, 536effects of partial postbacks, 324-328automatic disposal, 329-339manual disposal, 340-355

elements. See also controlsAllow, 429authorization, configuring, 428-429Deny, 429DOM, 9, 557Forms authentication, 427param attributes, 553

embedding JavaScript files, 215EnableScriptLocalization

property, 293

Page 53: Download the sample pages.pdf

enablingCurrencyTextBox.Res, 307script globalization, 281

EndRequest event, 567endUpdate method, 129Englisherror messages, 294formatting, 278

enumerationsitems, accessing, 73Microsoft AJAX Library, extending,

72-78equality, 16Error objects, 27Error.create statement, 59ErrorDataService Web service, 574ErrorEventArgs Client Class, 571ErrorHandle component, 351-355ErrorHandler client code, 569-575ErrorHandler component, 129-134errorshandlers, adding, 130invalidationOperation, 70JavaScript, 25-29Microsoft AJAX Library error types,

57-59nonPositive, 59notImplemented, 68popStackFrame, 59publishing, 27, 133throwing, 27, 59-60

evaluations, typeof, 20-21eventsAnimation class, 504bubbling, 154customizing, 90editors, 93errors, 28

handlersadding, 130attaching, 107predefining, 147wrapping in delegates, 147

HttpApplication, 566init, 190load, Sys.Application, 198-203names, descriptors, 212normalizing, 108, 111OnLoad, 537Parameters, applying, 145-148raising, 91raw, accessing, 112Sys.Application, 364-367UpdatePanel, 318

exceptions, unhandled, 28-29executingbase class methods, 48initializebase method, 64initializeBaseType method, 47structures, 502timeouts, 37

Expando properties, 12, 75explicit anonymous functions, 31-32explicit arguments, 22Extender Control Wizard,

231-233, 523ExtenderBase folder, 485ExtenderControl class, 220-233, 322ExtenderControlBase class, 492-494,

513-523ExtenderControlBaseDesigner{T}

class, 497-499, 517ExtenderControlEvent attribute, 489ExtenderControlProperty

attribute, 489

Index586

Page 54: Download the sample pages.pdf

Index 587

extendersbase classes for, 491-494controlsanimations, 532-543attaching, 231-233design-time support, 524-532

ImageRotator, 227, 332-337TextBoxWaterMark, 497

extendingASP.NET 2.0 AJAX Extensions, xxxbuilt-in types, 52arrays, 5559booleans, 52dates and numbers, 53strings, 54-55

Function objects, 65Microsoft AJAX Libraryclasses, 60-67enumerations, 72-78inheritance, 78-87interfaces, 67-72

Ffactory, HTTP handlers, 562-565FadeAnimation properties, 534Fielding, Roy, 373filesAjaxControlExtender.vsi, 484default resource, 271JavaScriptembedding, 215loading, 355-363

machine.config, 429scripts, 476-477web.config, 429

Filter.es-MX.js script tag, 315Filter.js file, 310Filter.Res object, 312filteringamounts, defining, 308Transactions page, 294

finally blocks, 28findComponent method, 179first-class objects, 5foldersaccessing, 440Animation, 485Common, 485ExtenderBase, 485

for…in loops, 11forceLayoutInIE property, 536forEach method, 56-57form feed characters, 8format method, 55formattingEnglish, 278numbers, 279objects, defining, 289strings, 288

forms, authentication, 426-429forward references, configuring, 197fps property, 536frameworks, server components,

394-400Frenchculture Transaction page, 276error messages, 295local resource file, 275

Function.createDelegate method, 114Function object, 5extending, 65types, declaring, 62-65

functionalityASP.NET 2.0 Provider Model,

429-431duplicate, 495ScriptControl class, adding, 233-246WebControl class, 234

functionsanonymous, generating, 34arguments, 16-25checkAmounts, 310

Page 55: Download the sample pages.pdf

creating, 5, 541get_OnLoadBehavior, 541objects, 11onComplete, 419private, 555scope, inducing, 36SetSecurityMessage, 442troubleshooting, 33_validateParams, 557

GGenerate Local Resources tool, 268generatinganonymous functions, 34HTML, 241

GenericAnimationBehaviorclass, 541

getBaseType, 84getBounds, 104getComponents method, 184-185getInterfaces type, 87getLocation, 104GetPropertyValue method, 516GetScript method, 213GetScriptDescriptors method, 488GetTransactions method, 260-261get_ prefix, 66get_OnLoadBehavior function, 541get_text method, 244globalization, scripts, 281-293globally handling errors, 29GridView control transactions, 259

Hhandlersadding, 541errors, 130eventspredefining, 147wrapping in delegates, 147

HTTP, 396-398, 477, 560-565

headers, Accept-Language, 262HeaderText property, 271hexadecimal sequences

(2 hex digits), 8hierarchiesCompositeControl class, 248ExtenderControl class, 222

horizontal tabs, 8Hovercard server controls, 341-351HTML (Hypertext Markup

Language) generation, 241HTTP (Hypertext Transfer Protocol)handlers, 396-398, 477, 560-565modules, 398, 565-568REST, 372-373

HttpApplication events, 566

IIHttpHandlerFactory interface, 563IHttpModule interface, 565IIS (Internet Information Service),

registering, 385Image URL Collection Editor, 529Image URL Editor, 530ImageRotator extender, 227creating, 514-517troubleshooting, 332-337

ImageURL Editor, 242implementinginterfaces, 78-87services, 381

implementsInterface type, 86implicit arguments, 21implicit conversion, 14inferences, 549inheritance, 46-49components. See componentsExtenderControlBase class, 518-520ExtenderControl class, 226-229initializing, 64interfaces, 68

Index588

Page 56: Download the sample pages.pdf

Index 589

Microsoft AJAX Library, 78-87properties, accessing, 47ScriptControl class, 240-243types, 226

init events, 190, 364-367initialize method, 129-130, 300initializeBase method, 64initializeBaseType function, 46initializeBaseType method, 47InitializeCulture method,

265-266, 283initializingcomponents, 339inheritance, 64messages, 327routines, 185-191, 195-198Sys.Application, 136

InlineScript property, 385installing Ajax Control Toolkits, 484instancesobjects, creating, 9parameters, creating, 42properties, adding, 40System.Globalization.CultureInfo,

262IntelliSense, 547client libraries, 549references, 548-549troubleshooting, 550

interfacesAPIs, 375membership login, 436roles, 443

IHttpHandlerFactory, 563IHttpModule, 565implementing, 78-87IScriptControl, 247-254IService1, 377Microsoft AJAX Library, 67-72public, declaring, 65-66REST, 372-373

service contracts, 377Sys.Component class, 125, 129creating components, 134-151defining new components, 129-134

Sys.Icontainer class, 177internalscontrolscreating, 250rendering, 251

GetScript method, 213Sys.Application, 170

Internet Explorer, Operation Abortederror, 192

interpreting JavaScript, 5intervalsclearing, 336delayed code execution, 30-38

invalidationOperation error, 70InvalidNumberMessage resource

file, 304Invariant culture, 286IscriptControl interface, 247-254IService1 interface, 377isImplementedBy type, 87isNaN method, 311isIntanceOfType, 84IsReusable property, 561isUserInRole method, 455items, accessing enumerations, 73

JJavaScriptAPIs, 533-536arguments, 16-20attributes, 4-6classes, 483delayed code execution, 30-38error handling, 25-29files, embedding, 215functions, arguments, 21, 24-25

Page 57: Download the sample pages.pdf

localization, 277dates, 279-280numbers, 278-279

object-oriented programming, 39-49objects, 9-15overview of, 4primitive data types, 6statements and files, loading, 355-363types, extending built-in, 52-59

JavaScript Object Notation. See JSON

JavaScriptSerialize, 389JSON (JavaScript Object Notation),

12-14, 531parameters, 470serialization, 388-394

K–Lkeywords, yield, 225KnownType attribute, 392, 412-413

labels, transactions, 259languages, 4-6. See also JavaScriptlibraries. See also Microsoft

AJAX LibraryATL (ActiveX Template Library), 524clients, IntelliSense, 549Extender Control template, 514-517parameterArray, 558references, IntelliSense, 548-549templates, extender controls, 223-225

lifecycles, applications, 394-395, 559-560

line numbers, 29load events, Sys.Application class,

198-203loadHandler method, 367loading JavaScript statements and

files, 355-363local resources, 268-276localeFormat method, 55

localizationASP.NET AJAX, 277-288determining what needs to be

localized, 257-261displayed values, 267-276JavaScript, 277dates, 279-280numbers, 278-279

overview of, 255-256running under particular cultures,

261-266scripts, 293-315static file models, 315

Localization.Transaction type, 260loginsclients, 451membership APIs, 436

Lookup method, 402loops, for…in, 11

Mmachine.config file, 429maintenanceProfile Maintenance page, 457profiles, 447scope, Microsoft AJAX Library,

112-116make parameter, 22Manage User screen, 437managementapplication lifecycles, 559-560components, 123, 177-185roles, 439-441users, 438Web Site Administration Tool,

431-432, 437manual disposal, 340-355master pages, 218maximumOpacity property, 536mechanisms, try-catch-finally, 25-27

Index590

Page 58: Download the sample pages.pdf

Index 591

membersinternal, Sys.Application, 170privateaccessing, 81default values, 41defining, 300

public, defining, 42Sys.Component class, 126Types, defining, 41

membership, ASP.NET 2.0, 425-437merging .NET ScriptComponent-

Descriptor classes, 210-213messagesdebugging, 325ErrorHandle components, 354error alerts, 302initialization, 327

meta:resourcekey tags, 272-273metadata services, 469methods$find, 180add_init, 195, 364AddAttributesToRender, 343addComponent, 177AddComponentProperty, 211AddElementProperty, 211AddScriptproperty, 212Animation class, 504arrays, extending, 55-59base classaccessing, 80calling, 82ErrorHandler components, 132-133executing, 48overriding, 81

beginCreateComponents, 189beginUpdate, 129bubbleSort, 68defining, 70testing, 71

clickEventHandler, 114-115

curry, 36declarative, animations using,

537-543deserialize, 416dispose, 130, 300doInitialize, 189editorAddedHandler, 92endUpdate, 129findComponent, 179forEach, 56-57format, 55, 301Function.createDelegate, 114get_text, 244getComponents, 184-185GetPropertyValue, 516GetScript, 213GetScriptDescriptors, 488GetTransactions, 260-261initialize, 129-130, 300initializeBase, 64initializeBaseType, 47InitializeCulture, 265-266, 283isNaN, 311isUserInRole, 455loadHandler, 367localeFormat, 55Lookup, 402Membership class, 434notifyScriptLoaded, 216_onBlur, 302onBubbleEvent, 154_onFocus, 302pageload, 201pages, 386-387parametersvalidating, 555-558zero, 31

parse, 52, 75-78parseLocale, 284-285ProcessRequest, 467, 561raiseBubbleEvent, 154

Page 59: Download the sample pages.pdf

recursive anonymous, 24registerClass, 86registerDisposableObject, 204-205registerEnum, 74registerInterface, 68registration, ScriptManager, 355-361removeComponent, 183-184Render, 236RenderContents, 240rotateImage, 230ScriptComponentDescriptor class,

211, 488-489serialize, 416set_parent, 153shortcuts, 104string.format, 288strings, extending, 54-55Sys.Application, 172-175Sys.Application.notifyScriptLoaded( ),

362-363Sys.Component class, 127Sys.Component.create, 135Sys.Debug, 96Sys.EventHandlerList, 89Sys.Services.AuthenticationService

class, 449Sys.Services.ProfileService class, 456Sys.Services.RoleService class, 453Sys.StringBuilder, 95Sys.UI.Behavior class, 159Sys.UI.Control class, 152Sys.UI.DomElement, 101Sys.UI.DomEvent, 109toLocaleString, 279toString, 77unregisterDisposableObject, 205WebRequest class, 417WebServiceProxy class, 415window.clearTimeout, 30window.pageLoad, 203XML comments, 551-554

Microsoft AJAX Library, xxixarchitecture, 401serialization, 415-416service proxies, 401-415WebRequest class, 417-424

programming, 51-52, 60classes, 60-67enumerations, 72-78extending built-in types, 52-59inheritance, 78-87interfaces, 67-72

scope, 112-116types, 88Sys.Debug, 96-101Sys.EventHandlerList, 88-94Sys.StringBuilder, 94-95Sys.UI.DomElement, 101-106Sys.UI.DomEvent, 107-111

minimumOpacit property, 536modelsASP.NET 2.0 Provider Model,

429-431equality, 16Prototype, 60classes, 60-67enmuerations, 72-78inheritance, 78-87interfaces, 67-72

Web Application Project Model, 445modifyingDOM, 192enumerations, 72multiple handlers, 91namespaces, 407prototypes, 44types, 412

modulesHTTO, 565-568HTTP, 398ScriptModule, 398

Index592

Page 60: Download the sample pages.pdf

Index 593

Mozilla Foundation implementation, 4

multiple handlers, modifying, 91multiple interfaces, implementing,

85-87MyHandler.axd path, 562MyHandlerFactory class, 563

Nnamesevents, 212properties, 210

namespacesCommunicationSupport, 466declaring, 61-62modifying, 407System.Runtime.Serialization, 389

namingcontainers, 249operations, 408properties, 489

.NETclasses, 483merging, 210-213

Netscape, 4new communication paradigm,

372-373new components, defining, 129,

132-134new line characters, 8nonPositive error, 59nonstandard error properties, 26normalizingevent, 111events, 108

notationJSON, 12-14parameters, 470serialization, 388-394

Object Literal Notation, 11notifyScriptLoaded method, 216

notImplemented error, 68null, 18assigning, 12

Number.parseLocaleFixed, 299NumberOnlyTextBox type, 164numbers, 7extending, 53JavaScript, localization, 278-279line, 29script globalization, 282

OObject Literal Notation, 11object-oriented JavaScript

programming, 39-49objectscomponents. See componentsError, 27first-class, 5formatting, defining, 289Functiondeclaring types, 62-65extending, 65

functions, 11inheritance, 46-49instances, creating, 9JavaScript, 9-15JSON serialization, 388-394properties, 10prototypes, modifying, 44serializing, 416Type, 61wrappers, 53XMLHTTP, 423

octal sequences (3 digits), 8onBubbleEvent method, 154OnClientClick, 310onComplete function, 419OnLoad event, 537onSuccess callback function, 403operation aborted errors, 191

Page 61: Download the sample pages.pdf

OperationContract attribute, 407operations, naming, 408operators, equality, 16output, HoverCard server controls,

343-351overriding base class methods, 81

Ppageload method, 201pagescontrols, adding, 246methods, 386-387script references, 397

Parallel animations, 502param element attributes, 553parameterArray, 558parameters$create method, 136constructors, 41, 63events, applying, 145-148instances, creating, 42JSON, 470make, 22methodsvalidating, 555-558zero, 31

properties, 140-145references, applying, 149-150types, applying, 136-139

parent properties, controls, 153parentNode pointer, 153parse method, 52, 75-78ParseChildren attribute, 526parseLocale method, 284-285partial page rendering, 318partial postbacks, 195, 318-324effects of, 324-328automatic disposal, 329-339manual disposal, 340-355

viewing, 322passing in dictionaries, 116

pathsMyHandler.axd, 562ScriptResource.axd, 306

patternsJSON serialization, 388-394REST, 372-373

placement of references, 548pointers, parentNode, 153popStackFrame error, 59post back, definition of, 372PostAcquireRequestStat event, 566PostAuthenticateRequest event, 566PostAuthorizeRequest event, 566postbackspartial, 195viewing, 322

PostMapRequestHandler event, 566PostReleaseRequestState event, 567PostRequestHandlerExecute

event, 566PostResolveRequestCache event, 566PostUpdateRequestCache event, 567predefiningevent handlers, 147functions, 31

prefixes, 148properties, 66

PreRequestHandlerExecuteevent, 566

preventing automatic disposal ofcomponents, 351-355

primitive data types, 6, 14privacy, 63private functions, 555private membersaccessing, 81default values and, 41defining, 300

ProcessData IntelliSense, 550processing method results, 471-473ProcessRequest method, 561

Index594

Page 62: Download the sample pages.pdf

Index 595

Profile Maintenance page, 457ProfileBase class, 445profilesASP.NET 2.0, 425-433services, 456-459

programmingAPIs, 375JavaScriptarguments, 16-20attributes, 4-6delayed code execution, 30-38error handling, 25-29function arguments, 21-25object-oriented, 39-49objects, 9-15overview of, 4primitive data types, 6

Microsoft AJAX Library, 51-52, 60classes, 60-67enumerations, 72-78extending built-in types, 52-59inheritance, 78-87interfaces, 67-72scope, 112-116Sys.Debug type, 96-101Sys.EventHandlerList type, 88-94Sys.StringBuilder type, 94-95Sys.UI.DomElement type, 101-106Sys.UI.DomEvent type, 107-111types, 88

properties$create statements, assigning, 243accessing, 47Animation class, 503callee, 24caller, 24ClientPropertyName, 489constructor, 15CurrentCulture/CurrentUICulture,

262defining, 300

designers, adding to, 526-532editors, adding to, 526-532EnableScriptLocalization, 293Expando, 12, 75extender controls, 525ExtenderControlBase class, 492HeaderText, 271InlineScript, 385instances, adding, 40IsReusable, 561localization, 271Membership class, 433naming, 210, 489nonstandard error, 26objects, 10parameters, applying, 140-145parent controls, 153prefixes, 66proxy class, 404Roles class, 442ScriptReference class, 217ServiceReference, 385standard error, 26Sys.CultureInfo class, 290Sys.Net.XMLHttpExecutor class, 422Sys.Services.AuthenticationService

class, 449Sys.Services.ProfileService class, 456Sys.Services.RoleService class, 453undefined, 41WebControl class, 236WebRequest class, 417WebServiceError class, 403WebServiceProxy class, 415

properties property, 456protocol-based methods, defining, 43protocols, HTTPhandlers, 396-398modules, 398REST, 372-373

Page 63: Download the sample pages.pdf

Prototype Model, 60classes, extending, 60-67enumerations, extending, 72-78inheritance, extending, 78-87interfaces, extending, 67-72

prototypes, 44serialization, 416

proxy classes, services, 401-415, 473-477

public interfaces, declaring, 65-66public members, defining, 42publishing errors, 27

Q–RraiseBubbleEvent method, 154raising events, 91raw events, accessing, 112reading JSON data, 390reconstructing method calls, 469-471recursive anonymous methods, 24referencesassigning, 149configuring, 196-198designers, 527IntelliSense, 548-549page scripts, 397parameters, applying, 149-150types, 548

regions, 255. See also localizationregisterClass method, 86registerDisposableObject method,

204-205registerEnum method, 74registerInterface method, 68registrationanimation scripts, 533classes, 79enumeration, 74globalization script blocks, 291HTTP Handler, 562-565methods, ScriptManager, 355-361

product class, 409ScriptManager control, 218-219scripts, 220, 509services, 384-385types, 66-67

ReleaseRequestState event, 567removeComponent method, 183-184Render method, 236RenderContents method, 240renderinginternal controls, 251partial page, 318

Representational State Transfer(REST), 372-373

requestsHTTPhandlers, 560-565modules, 565-568

timeouts, 405RequiredProperty attribute, 489RequiredScripts attribute, 538requirements, registration, 67ResolveRequestCache event, 566resourceslocal, 268-276REST, 372-373scripts, 214-219

REST (Representational StateTransfer), 372-373

restricting access, using roles, 441retrieving components, 184-185rolesASP.NET 2.0, 425-433services, 453-454

RootNamespace.PathTo-JavaScriptFile, 216

rotateImage method, 230routinesSys.Application, initializing, 185-198unload, Sys.Application, 203-206

Index596

Page 64: Download the sample pages.pdf

Index 597

Ssample website, 485scopeanonymous functions, 34Microsoft AJAX Library, 112-116troubleshooting, 35variables, 16-18

script-generation architecture, 208behavior and control, 208-218resources, 214-219

ScriptBehaviorDescriptor class, 213, 389

ScriptComponentDescriptor class,210-213, 389

methods, 488-489ScriptControl class, 233-246, 322,

491-494ScriptControlBase class, 495ScriptControlDescriptor class, 208,

214, 389ScriptHandlerFactory class, 396ScriptManager class, 218-219page methods, configuring, 387registration methods, 355-361services, registering, 384

ScriptManagerProxy control, 218-219ScriptModule module, 398ScriptReference class, 216ScriptReference values, 490-491ScriptResource attribute, 305ScriptResource.axd paths, 306ScriptResourceHandler, 307, 396scriptsanimationcalling, 534-536registration, 533

caching, 306controls, creating, 237-246dispose, 337-339files, 476-477Filter.es-MX.js, 315

globalization, 281-293JSON, 12-14localization, 293-315page references, 397registering, 509

SearchCriteria class, 381searching components, 179-183security, Forms authentication,

426-429Sequence animations, 502serializationASP.NET 2.0 AJAX Extensions,

388-394DataContractJsonSerializer, 531Microsoft AJAX Library

communication architecture,415-416

type converters, creating to support,530-532

serialize method, 416server-based architecture, Toolkit

(ASP.NET AJAX Control), 486attributes, 486-491base classes for extenders, 491-494designer classes, 495-499

server-side JavaScript. See SSJSserverscontrols, xxvii, xxxiiiErrorHandler, 571-572HoverCard, 341-351

framework components, 394-400Service1 class, 377ServiceCommunication

assembly, 477ServiceHandlerFactory HTTP

handler factory, 462ServiceReference class

properties, 385servicesAJAX-enabled WCF, 382applications, customizing, 460-478

Page 65: Download the sample pages.pdf

ASP.NET 2.0, 425-433ASP.NET AJAX application

services, 448authentication, 448-452profiles, 456-459roles, 453-454

contracts, 376-378creating, 381-383

implementing, 381metadata, 469proxies, 401-415proxy classes, 473-477registering, 384-385web, 375-386Web Site Administration Tool,

431-437set_parent method, 153SetSecurityMessage function, 442setTimeout, 31shortcuts, methods, 104signatures, methods, 211SimpleBehavior, 329SimpleComponent control, 327SimpleWCFService proxy class, 473single quote (‘), 8skeletons, creating, 129-130Spanishculture Transaction page, 276error messages, 315local resource file, 275

special characters, 8special number values, 7SSJS (server-side JavaScript), 4stacks, call, 190StackTrace Client class, 572-573standard error properties, 26standards, ECMAScript, 4starting initialization routines, 186state, 493

statements$create, assigning properties, 243Error.create, 59JavaScript, loading, 355-363try-catch, 26

static file models, 315string.format method, 267, 288strings, 8concatenation, 9data format, 289extending, 54-55JSON, 531script globalization, 288-290variables, declaring, 8viewing, 268-276

structuresanimations, 502-503execution, 502

styles, WebControl class, 236summary tag, 551Sun Microsystem Java programming

language, 4supportanimations, 483declarative methods, 538extender controls, adding

design-time to, 524-532IScriptControl interfaces, 252type converters, creating, 530-532

syntax, declarative methods, 537Sys.Application class, 169components, managing, 177-185creating, 170-172events, 364-367initialization routines, 136, 185-198load events, 198-203method information, 172-175type information, 172unload routines, 203-206

Index598

Page 66: Download the sample pages.pdf

Index 599

Sys.Application.dispose, 203-206Sys.Application.notifyScriptLoaded( )

method, 362-363Sys.ApplicationLoadEventArgs

members, 199Sys.Component class, 125, 129components, 134-151new components, defining, 129-134

Sys.Component.create method, 135Sys.CultureInfo class, 290-293Sys.Debug type, 96-101Sys.EventArgs class, 93Sys.EventHandlerList type, 88-94Sys.IContainer interface, 177Sys.Net.WebProxy class, 449, 456Sys.Net.WebRequestManager

class, 422Sys.Net.XMLHttpExecutor class, 422Sys.Serialization.JavaScript-

Serializer, 415Sys.Services.AuthenticationService

class, 449Sys.Services.ProfileService class, 456Sys.Services.RoleService class, 453Sys.StringBuilder type, 94-95Sys.UI.Behavior class, 208-218creating, 229-230method, 159

Sys.UI.Behavior template class, 225Sys.UI.Control class, 122, 152,

208-218, 244-246Sys.UI.DomElement type, 101-106Sys.UI.DomEvent type, 107-111System.ComponentModel.

EventHandlerList, 89System.Globalization.CultureInfo

instance, 262System.Runtime.Serialization

namespace, 389System.ServiceModel.Activation.

HttpHandler, 397-398System.Web.UI.Design.ToolboxItem

attribute, 539

Ttagsdiv, wrapping HoverCards in, 346Filter.es-MX.js, 315meta:resourcekey, 272-273summary, 551

target property, 536templatesAJAX-enabled WCF service, 382ATL, 524Extender Control library, 514-517libraries, extender controls, 223-225

testingbubbleSort method, 68-71error pages, 574-575

TestType, defining, 83TextBoxInfo class, 244-246TextBoxInfo control, 240TextBoxWaterMark extender, 497throwing errors, 27, 59-60timeouts, 190delayed code execution, 30-38requests, 405

toLocaleString method, 279Toolkit (ASP.NET AJAX Control)

architecture, 481animations, 501-512client-based, 499-501composition of, 483-486overview of, 482-483server-based, 486-499

Toolkit library project, 484-485toolsASP.NET AJAX Control Toolkit, xxxGenerate Local Resources, 268Web Site Administration Tool,

431-440toString method, 77tracing Sys.Debug, 97-98TransactionDataSource, 260

Page 67: Download the sample pages.pdf

transactionsGridView control, 259labels, 259localization, 257

Transactions.aspx file, 257-260, 271-273

Transactions class, 260-261, 294transfers, REST, 372-373troubleshootingDOM, modifying, 192functions, 33ImageRotator extenders, 332-337IntelliSense, 550operation aborted errors, 191page methods, 387scope, 35variables, 33

try-catch-finally mechanism, 25, 27try-catch statements, 26typesanimations, 502-503behaviors, 159-161creating, 162-167defining, 161-162

built-inarrays, 55-59booleans, 52dates and numbers, 53extending, 52strings, 54-55

of contracts, 376data, 378-379service, 376-378

controlscreating, 157-159defining, 155-157

converters, creating, 530-532data, abstract, 40-45declaring, 62-65defining, 40, 63EventArgs, creating custom, 93

getBaseType, 84getInterfaces, 87informationJSON, 392Sys.Application, 172

inheritance, 226inheritsFrom, 83instanceOfType, 84isImplementedBy, 87of JavaScript, 4KnownType attribute, 412-413Localization.Transaction, 260members, defining, 41Microsoft AJAX Library, 88Sys.Debug, 96-101Sys.EventHandlerList, 88-94Sys.StringBuilder, 94-95Sys.UI.DomElement, 101-106Sys.UI.DomEvent, 107-111

modifying, 412NumberOnlyTextBox, 164parameters, applying, 136-139primitive data, 6, 14references, 548registration, 66-67Type object, 61

Uundeclared variables, 18undefined arguments, 18, 22undefined properties, 41underscore (_), 64unhandled exceptions, 28-29Unicode sequence (4 hex digits), 8Uniform Resource Identifiers.

See URIsunload routines, Sys.Application

class, 203-206unregisterDisposableObject

method, 205

Index600

Page 68: Download the sample pages.pdf

Index 601

UpdatePanelbehavior, 318-324JavaScript statements and files,

loading, 355-363partial postbackseffects of, 324-328automatic disposal, 329-339manual disposal, 340-355

UpdateRequestCache event, 567URIs (Uniform Resource

Identifiers), 380UrlProperty attribute, 241UserProfile class, 445usersadding, 437ASP.NET 2.0, 425-433editing, 438managing, 438

Vvalidatingmethod parameters, 555-558parameterArray, 558

valuesdisplayed, localizing, 267-276private members, 41ScriptReference, 490-491special number, 7undefined, 18

variablesadding, 540arguments, 16-20__cultureInfo, 292strings, declaring, 8troubleshooting, 33

view state, 493viewingerror messages, 302partial postbacks, 322strings, 268-276

Visual Studiocontrol library template, 237-240Extender Control library template,

223-225, 514-517IntelliSense, 547client libraries, 549references, 548-549troubleshooting, 550

resource files, 304

WWCF (Windows Communication

Foundation), 375-386, 486WCFHandler class, 465Web Application Project Model, 445web applications, xxviiconfiguring, 398-400

web.config file, 429Web Development Helper, 322web services, 375-386ErrorDataService, 574

Web Site Administration Tool, 431-432, 437

role management, 440WebControl class, 234WebRequest class, 417-424WebResource attribute, 216WebServiceError class

properties, 403WebServiceProxy class

properties, 415Website Administration Tool

Security tab, 432websitessamples, 485Toolkit, 486

window.pageLoad method, 203Windows Communication

Foundation (WCF), 375-386, 486

Page 69: Download the sample pages.pdf

wizards, Extender Control Wizard,231-233, 523

wrappers, objects, 14, 53wrappingevent handlers in delegates, 147HoverCards in div tags, 346

writing JSON data, 391

X–ZXML (Extensible Markup Language)

comments, 551-554XMLHTTP object, 423

yield keyword, 225

zero parameter methods, 31

Index602