Advanced ASP.NET AJAX Server Controls, For .NET Framework 3.5 (2009)

Advanced ASP.NET AJAX Server Controls, For .NET Framework 3.5 (2009)

(Parte 2 de 5)

Figure 7.20ErrorHandler’s initialization and disposal messages354 Figure 7.21Partial page-rendering sample360 Figure 7.22Alert from ClientScriptManager registration in page load361 Figure 7.23Alert from ScriptManager registration in page load361 Figure 7.24UpdatePanel response shown in Web Development Helper362 Figure 7.25The output of the loadHandler method367 Figure 7.26The output of the loadHandler method367

Figure 8.1ASP.NET AJAX server communication architecture375 Figure 8.2AJAX-enabled WCF service template382

Cont ent sxviii

Figure 8.3ASP.NET application lifecycle395 Figure 8.4Microsoft AJAX Library communication architecture401

Figure 9.1Web Site Administration432 Figure 9.2Web Site Administration Tool Security tab432 Figure 9.3Membership login sample 436 Figure 9.4Create users using the Web Site Administration Tool437 Figure 9.5Managing users using the Web Site Administration Tool438 Figure 9.6Editing users using the Web Site Administration Tool438 Figure 9.7Role management using the Web Site Administration Tool440 Figure 9.8Managing access using roles441 Figure 9.9Restricting access using roles441 Figure 9.10Profile Maintenance page447 Figure 9.11Order entry screen451 Figure 9.12Client-side login451 Figure 9.13AJAX Profile Maintenance page458 Figure 9.14Custom application service server architecture461 Figure 9.15Custom application service client architecture462 Figure 9.16ServiceHandlerFactory HTTP handler463 Figure 9.17ServiceCommunication project structure466 Figure 9.18CommunicationSupport namespace classes467

Figure 10.1ASP.NET AJAX Control Toolkit attributes487 Figure 10.2ASP.NET AJAX Control Toolkit extender and ScriptControl base classes 491

Figure 10.3ASP.NET AJAX Control Toolkit design-time classes496 Figure 10.4Design-time experience with extender controls497 Figure 10.5Adding the AutoComplete page method smart tag action498 Figure 10.6ASP.NET AJAX Control Toolkit JavaScript class hierarchy500 Figure 10.7ASP.NET AJAX Control Toolkit animation containers505 Figure 10.8ASP.NET AJAX Control Toolkit animations507 Figure 10.9ASP.NET AJAX Control Toolkit animation actions508 Figure 10.10ASP.NET AJAX Control Toolkit declarative animation support classes 510

Cont ent s xix

Figure 1.1Extender control project template515 Figure 1.2Extender control project template structure515 Figure 1.3Extender Control Wizard524 Figure 1.4Extender properties on the image control525 Figure 1.5Image URLCollection Editor529 Figure 1.6Image URLEditor530

Figure A.1ProcessData IntelliSense550 Figure A.2 Books.Publishers.Publisher IntelliSense 550 Figure A.3Constructor’s IntelliSense for completion list552 Figure A.4Constructor’s IntelliSense underneath during selection552 Figure A.5IntelliSense completion list554 Figure A.6Parameter IntelliSense554

Figure C.1ASP.NET application lifecycle560

Cont ent sxx

Tables

Table 1.1Special Number Values7 Table 1.2Special Characters8 Table 1.3typeof Evaluations20 Table 1.4Standard Error Properties26 Table 1.5Nonstandard Error Properties26 Table 2.1Results of the parse Method53 Table 2.2New String Type Methods54 Table 2.3New Array Type Methods55-56 Table 2.4Existing Error Types58 Table 2.5Sys.EventHandlerList Methods89 Table 2.6Sys.StringBuilder Methods95 Table 2.7Sys.Debug Methods96 Table 2.8Available Debug Consoles99 Table 2.9Sys.UI.DomElement Methods102 Table 2.10Attaching Event Handlers to DOM Element Events107 Table 2.11Sys.UI.DomEvent Methods109 Table 2.12Sys.UI.DomEvent Properties110 Table 3.1Differences between Components, Controls, and Behaviors124 Table 3.2Interfaces Implemented by Sys.Component126 Table 3.3Sys.Component Members126 Table 3.4Sys.Component Methods127-128 Table 3.5Sys.UI.Control Methods152 xxi

Table 3.6Sys.UI.Control Methods Related to Control’s Parent154 Table 3.7Sys.UI.Control Methods Related to Event Bubbling155 Table 3.8Sys.UI.Behavior Methods159-160 Table 4.1Sys.Application Internal Members171 Table 4.2Sys.Application Methods173-174 Table 4.3 Sys.ApplicationLoadEventArgs Members 199 Table 5.1 ScriptComponentDescriptor Properties 210 Table 5.2 ScriptComponentDescriptor Methods 211 Table 5.3ScriptReference Properties217 Table 6.1New Number Type Methods282 Table 6.2New Date Type Methods286 Table 6.3Sys.CultureInfo Properties291 Table 7.1ScriptManager Script Registration Methods356 Table 8.1Properties of the ServiceReference Class385 Table 8.2Constructors of the DataContractJsonSerializer390 Table 8.3Subset of Methods of the DataContractJsonSerializer391 Table 8.4Properties of the WebServiceError Class403 Table 8.5Proxy Class Properties404 Table 8.6WebServiceProxy Class Properties415 Table 8.7WebServiceProxy Class Methods415 Table 8.8WebRequest Class Properties417-418 Table 8.9WebRequest Class Methods418 Table 8.10XMLHttpExecutor Class Properties422-423 Table 8.11XMLHttpExecutor Class Methods423 Table 9.1Forms Authentication Elements427-428 Table 9.2Deny and Allow429 Table 9.3Provider Services and Default Classes430 Table 9.4Common Membership Class Properties433-434 Table 9.5Common Membership Class Methods434-435 Table 9.6Membership Controls435-436

Cont ent sxxii

Table 9.7Common Roles Class Properties442 Table 9.8Common Roles Class Methods443 Table 9.9 AuthenticationService Properties 449 Table 9.10 AuthenticationService Methods 450 Table 9.11RoleService Properties454 Table 9.12RoleService Methods454 Table 9.13ProfileService Properties457 Table 9.14ProfileService Methods457 Table 10.1Attributes and ScriptComponentDescriptor Methods Comparison488 Table 10.2 ScriptReference-Related Attributes 490 Table 10.3ExtenderControlBase Core Properties492 Table 10.4Animation Properties504 Table 10.5Animation Methods504 Table 10.6Animation Events504 Table 1.1Partial List of Fade Animation Class Properties536 Table A.1Param Element Attributes 553 Table C.1HttpApplication Events566

Cont ent s xi

Foreword

THEASP.NET PLATFORMPOWERSmillions of websites around the world today, and is perhaps one of the most productive platforms for web development. During the nearly ten years of its development and use, ASP.NET has formed around itself a strong community and vibrant ecosystem of developers.

The page framework and the associated server controls framework are quintessential to the success of ASP.NET and its developer experience, programming model, and extensibility. Writing this Foreword brings back memories of early ASP.NET days, and reminds me of the continued evolution 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 and varying degrees of capabilities (remember HTML3.2?), and concepts such as “stateless programming model” presented an odd paradigm shift. Server controls provided a set of familiar abstractions and created a componentbased rapid application development (RAD) programming experience for the Web (à la Visual Basic) and allowed developers to feel at home as they started to look to the Web to build the next generation of data-driven applications.

Flash forward a few years, and in 2006, the AJAX buzz created a renewed interest in the Web as theapplication platform. Today, AJAX is mainstream and, quite literally, everywhere. It enables building interactive experiences that users have come to expect. Still, it brings new but similar xxv challenges: varying browser APIs and an unfamiliar script-based programming model. Once again, ASP.NET (and in particular, server controls) provided a mechanism for creating a productive development model for incorporating AJAX-based techniques, and for encapsulating server and client behaviors into a familiar and consistent component model.

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

In this book, Adam and Joel focus on providing a beyond-the-basics drill down of the inner workings and extensibility of the ASP.NET AJAX framework by covering the programming patterns established by the script framework, the architecture, and the techniques to create AJAX-enabled server controls. They also cover advanced but still relevant topics such as localization and error handling. By providing a conceptual guide to understanding and extending the framework, this book is sure to serve any application or component developer who is looking to unlock the true potential of ASP.NET AJAX.

—Nikhil Kothari Software Architect .NET Developer Platform, Microsoft

Forewordxxvi

Preface

Introduction

SERVERCONTROLSAREANINTEGRALaspect of every ASP.NET application we build. They encapsulate browser appearance and server functionality in a reusable object. They can be used across multiple pages within a single ASP.NET application and across multiple ASP.NET applications. ASP.NET comes with a lot of prebuilt server controls. We have simple controls 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 of the existing controls by inheriting from the appropriate base class and overriding its methods as needed.

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

Anew server control need that has recently surfaced is the ability to incorporate AJAX functionality directly into the server control.

This need arose because our web applications need to be more responsive and visually interactive than the traditional ASP.NET repaint-theentire-screen model and therefore the traditional server control supplies. This requirement has emerged because users are using websites such as Gmail, Live.com, Yahoo! Mail, and others that don’t repaint the screen every time they click a button or need to receive fresh data. Rather, they rely xxvii on AJAX to fetch fresh data and then update or add to a portion of the screen based on that data. Because these websites are heavily used and users really enjoy their experience while using these websites, they expect other websites to perform with the same elegance as their favored sites do. When a website doesn’t perform with the same elegance, the user often moves on to another website that does. Those popular applications have raised the bar for what is an acceptably user-friendly website.

Because our users are demanding a website experience that essentially uses AJAX and we build our ASP.NET websites using server controls, we need a way of easily creating server controls that not only encapsulate browser appearance and server functionality, but also include AJAX functionality so that the server control itself is AJAX-enabled.

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

There were a few different methods we could use to include the

JavaScript with our server control such as embedding it as a resource, but we eventually ended up having to do the same three tasks. To make our server control have some serious client capabilities, we always had to concatenate strings together to form JavaScript statements and functions, write browser sniffing statements to make sure that the JavaScript was crossbrowser compatible, and add attributes or render out HTMLthat attached the JavaScript functionality to the client versions of our server controls. It wasn’t impossible, but it was error-prone, and there was always this mingling of server code and JavaScript that was hard to maintain and even harder to read.

Furthermore, if you had multiple server controls that had client capabilities, it was difficult (but not impossible) to ensure that the client functions that each server control required didn’t overwrite each other when rendered on the browser. Tracking down that problem was always a fun hour or so.

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

Prefacexxviii a button embedded in the server control. Even with a helper communication library, there were always tricks to getting your control to communicate properly with the server.

These hindrances were problematic enough to lead to some bad programming habits and bad code and to scare programmers away from even attempting 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 both server and client programming constructs that make adding AJAX capabilities to our server controls easy. Not to sound cliché, but with ASP.NET AJAX reducing the complexity of adding AJAX capabilities to our server controls, we can create server controls whose AJAX capabilities are limited only 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 the server, or if we want a button that submits an address for verification, we can easily accomplish these things through ASP.NET AJAX.

The ASP.NET AJAX Components

As we go through the book we’llbe talking about the three parts of ASP.NET AJAX: the Microsoft AJAX Library, the ASP.NET 2.0 AJAX Extensions, and the ASP.NET AJAX Control Toolkit. Here’s a quick rundown of the different components.

Microsoft AJAX Library The Microsoft AJAX Library isthe JavaScript programming framework of ASP.NET AJAX. It provides al the client programming constructs you’l use 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

ASP.NET 2.0 AJAX Extensions The ASP.NET 2.0 AJAX Extensions are server objects such as the Script Manager,ScriptControl, and ScriptDescriptor, which provide a connection between the Microsoft AJAX Library and our server ASP.NET development. These server objects provide an important distinction between ASP.NET AJAX and other AJAX frameworks because they provide a server programming model for manipulating client code (and allow us to make AJAX-enabled server controls!). Like the Microsoft AJAX Library, they are included in the System.Web.Extensions DLL.

ASP.NET AJAX Control Toolkit The ASP.NET AJAX Control Toolkit is a shared source project that is built on top of ASP.NET AJAX. It’s an effort shared between Microsoft and the ASP.NET AJAX community with the goal of developing powerful and reusable ASP.NET AJAX extenders and controls.

(Parte 2 de 5)

Comentários