Server controls are an integral aspect 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 as well as 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 also have the ability to 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.
A new 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-the-entire-screen model and therefore the traditional server control supplies. This requirement has emerged because users are using web sites 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 on Ajax to fetch fresh data and then update or add to a portion of the screen based upon that data. Because these web sites are heavily used and users really enjoy their experience while using these websites they expect other web sites to perform with the same elegance as they do. When a web site doesn't perform with the same elegance the user will often move onto another web site that does. Those popular applications have raised the bar for what is an acceptably user-friendly web site.
Because our users are demanding a web site experience that essentially uses Ajax and we build our ASP.NET web sites 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 on, 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.
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 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 as well as scare programmers away from even attempting to include Ajax-functionality in their server controls.
These problems are what Microsoft's ASP.NET AJAX solves.
In this book, we're going to 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're able to create server controls whose Ajax capabilities are only limited by our creativity. If we want to 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 submits an address for verification we can easily accomplish this through ASP.NET AJAX.
The ASP.NET AJAX Components
As we go through the book we'll be talking about the three sections 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
ASP.NET 2.0 AJAX Extensions
The ASP.NET 2.0 AJAX Extensions are server objects such as the ScriptManager, 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 as 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 in with the goal of developing powerful and reusable ASP.NET AJAX extenders and controls.
It's not actually part of ASP.NET AJAX, but because it provides so many great server and extender controls, it's invaluable to the ASP.NET AJAX community. Creating new extender controls through it will be a topic we'll cover fully.
Starting in Chapter 3 we begin our path to creating fully encapsulated Ajax-enabled controls by learning how to use and derive from three key client types: Components, Controls, and Behaviors. We'll talk theory as well as provide a couple of practical examples.
In Chapter 4 we cover maybe the most important portion of the Microsoft AJAX Library as we cover Sys.Application and how it acts like a client runtime with which we can interact.
Finally, in Chapter 5 we bring the server into the mix when we cover how to create server Components, Controls, and Behaviors that automatically create their corresponding client objects.
In Chapter 6 we wrap up the Controls section with an in-depth examination of Localization in ASP.NET AJAX.
With Chapter 7 we start looking at communication in ASP.NET AJAX using WCF services, page methods, and the client web service proxies.
In Chapter 8 we cover the application services and include a demonstration on how to build your own application service.
In Chapter 9 we conclude our communication section with a look at some of the concerns surrounding how the UpdatePanel effects control development.
Ajax Control Toolkit
Beginning with Chapter 10 we start our look at the Ajax Control Toolkit. We cover the base classes that are used by toolkit controls as well the support and designer classes that provide additional features.
Finally, we conclude the book with Chapter 11 as we attach client capabilities to server controls using the Ajax Control Toolkit. This chapter includes how to build a new extender control and provide design time features for it.
What is not covered?
You might find it strange to see a section that talks about what we're not covering. We're including it for two reasons.
First, this book covers a pretty narrow topic when compared to ASP.NET AJAX at large. Because of this we don&...