What Is ASP.NET AJAX?


ASP.NET AJAX is Microsoft’s implementation of the Ajax framework and is specifically targeted at ASP.NET developers. It is available, along with documentation, forums, and sample code, from the Web site http://ajax.asp.net.

ASP.NET AJAX provides the following functionality:

  • A server-side framework that enables ASP.NET Web pages to respond to partial-page postback operations.

  • ASP.NET server controls that make the implementation of Ajax functionality easy.

  • An HTTP handler that enables ASP.NET Web services to communicate with client-side code by using JavaScript Object Notation (JSON) serialization in partial-page postback operations.

  • Web services that enable client-side code to gain access to ASP.NET application services, including authentication and personalization services.

  • A Web site template for creating ASP.NET AJAX-enabled Web applications.

  • A client-side JavaScript library that provides a number of enhancements to JavaScript syntax as well as code to simplify the implementation of Ajax functionality.

These server controls and the server-side framework that makes them possible are collectively known as the ASP.NET Extensions. The client-side part of ASP.NET AJAX is known as the AJAX Library. The AJAX Library can be used independently of the server-side functionality and can even be used in non-ASP.NET scenarios such as PHP Web applications, although this subject is beyond the scope of this chapter.

This is all part of the core ASP.NET AJAX functionality and at the time of writing is available in the ASP.NET AJAX 1.0 RTM download. At some point in the future, this core functionality will be made part of ASP.NET rather than being a separate package.

Tip 

The next version of ASP.NET, which will include ASP.NET AJAX, is currently known by the code-name “Orcas.” As well as including ASP.NET AJAX functionality, the next version of Visual Studio will also include enhanced support and debugging features for client-side JavaScript.

There are also two additional downloads that you can obtain from the same place:

  • ASP.NET AJAX Control Toolkit - This download contains additional server controls that have been created by the developer community. These controls are shared-source controls that you can inspect and modify as you see fit. This download also includes an SDK for creating your own server controls.

  • ASP.NET 2.0 AJAX Futures CTP - This download, which changes frequently, contains additional client-side and server-side functionality that remains in development. Much of this functionality may at some point become part of the core download.

Together these downloads provide you with a richly featured framework that you can use to add Ajax functionality to your ASP.NET Web applications. In the following sections, you’ll learn more about what is contained in the various component parts of ASP.NET AJAX.

Core Functionality

The core functionality of ASP.NET AJAX is divided into two parts, the AJAX Extensions and the AJAX Library.

AJAX Extensions

When you install ASP.NET AJAX, two assemblies are installed in the GAC:

  • System.Web.Extensions.dll - This assembly contains the ASP.NET AJAX functionality, including the AJAX Extensions and the AJAX Library JavaScript files, which are available through the ScriptManager component (which is described shortly).

  • System.Web.Extensions.Design.dll - This assembly contains ASP.NET Designer components for the AJAX Extensions server controls. This is used by the ASP.NET Designer in Visual Studio or Visual Web developer.

Much of the AJAX Extensions component of ASP.NET AJAX is concerned with enabling partial-page postbacks and JSON serialization for Web services. This includes various HTTP handler components and extensions to the existing ASP.NET framework. All of this functionality can be configured through the Web.config file for a Web site. There are also classes and attributes that you can use for additional configuration. However, most of this configuration is transparent, and you will rarely need to change what is supplied in, for example, the ASP.NET AJAX-Enabled Web Site template.

You main interaction with AJAX Extensions will be by using server controls to add Ajax functionality to your Web applications. There are several of these, which you can use to enhance your applications in various ways. The following table shows a selection of the server-side components. You will see these components in action later in this chapter.

Open table as spreadsheet

Control

Description

ScriptManager

This control is central to ASP.NET AJAX functionality and is required on every page that uses partial-page postbacks. Its main purpose is to manage client-side references to the AJAX Library JavaScript files, which are served from the ASP.NET AJAX assembly. The AJAX Library is used extensively by the AJAX Extensions server controls, which all generate their own client-side code.

This control is also responsible for the configuration of Web services that you intend to access from client-side code. By supplying Web service information to the ScriptManager control, you can generate client-side and server-side classes to manage asynchronous communication with Web services transparently.

You can also use the ScriptManager control to maintain references to your own JavaScript files and to the additional JavaScript files included in the Futures CTP.

UpdatePanel

The UpdatePanel control is an extremely useful one and is perhaps the ASP.NET control that you will use most often. This control acts like a standard ASP.NET placeholder and can contain any other controls. More importantly, it also marks a section of a page as a region that can be updated independently of the rest of the page, in a partial-page postback.

Any controls contained by an UpdatePanel control that cause a post-back (a Button control, for example) will not cause full-page postbacks. Instead, they cause partial-page postbacks that will update only the contents of the UpdatePanel.

In many situations, this control is all you need in order to implement Ajax functionality. For example, you can place a GridView control in an UpdatePanel control and any pagination, sorting, and other postback functionality of the control will take place in a partial-page postback.

UpdateProgress

This control enables you to provide feedback to users when a partial page postback is in progress. You can supply a template for this control that will be displayed when an UpdatePanel is updating. For example, you could use a floating <div> control to display a message such as “Updating” so that the user is aware that the application is busy. Note that partial-page postbacks do not interfere with the rest of a Web page, which will remain responsive.

Timer

The ASP.NET AJAX Timer control is a useful way to cause an UpdatePanel to update periodically. You can configure this control to trigger postbacks at regular intervals. If this control is contained in an UpdatePanel control, then the UpdatePanel will be updated every time the Timer control is triggered. This control also has an associated event so that you can carry out periodic server-side processing.

AsyncPostBackTrigger

You can use this control to trigger UpdatePanel updates from controls that aren’t contained in the UpdatePanel. For example, you can enable a drop-down list elsewhere on a Web page to cause an UpdatePanel containing a GridView control to update.

The AJAX Extensions also include the ExtenderControl abstract base class for extending existing ASP.NET server controls. This is used, for example, by various classes in the ASP.NET 2.0 AJAX Futures CTP, as you will see shortly.

AJAX Library

The AJAX Library consists of JavaScript files that are used by client-side code in ASP.NET AJAX-enabled Web applications. There is a lot of functionality included in these JavaScript files, some of which is general code that enhances the JavaScript language and some of which is specific to Ajax functionality. The AJAX Library contains layers of functionality that are built on top of each other, as shown in the following table.

Open table as spreadsheet

Layer

Description

Browser compatibility

The lowest-level code in the AJAX Library consists of code that maps various JavaScript functionality according to the client Web browser. This is necessary because there are differences in the implementation of JavaScript in different browsers. By providing this layer, JavaScript code in other layers does not have to worry about browser compatibility, and you can write browser-neutral code that will work in all client environments.

Core services

This layer contains the enhancements to the JavaScript language, in particular OOP functionality. By using the code in this layer you can define namespaces, classes, derived classes, and interfaces using JavaScript script files. This is of particular interest to C# developers, as it makes writing JavaScript code much more like writing .NET code with using C# and encourages reusability.

Base class library

The client base class library (BCL) includes many JavaScript classes that provide low-level functionality to classes further down the AJAX Library hierarchy. Most of these classes are not intended to be used directly.

Networking

Classes in the networking layer enable client-side code to call server-side code asynchronously. This layer includes the basic framework for making a call to a URL and responding to the result in a callback function. For the most part, this is also functionality that you will not use directly; instead you will use classes that wrap this functionality. This layer also contains classes for JSON serialization and deserialization. You will find most of the networking classes on the client side Sys.Net namespace.

User interface

This layer contains classes that abstract user interface elements such as HTML elements and DOM events. You can use the properties and methods of this layer to write language-neutral JavaScript code to manipulate Web pages from the client. User interface classes are contained in the Sys.UI namespace.

Controls

The final layer of the AJAX Library contains the highest-level code, which provides Ajax behaviors and server control functionality. This includes dynamically generated code that you can use, for example, to call Web services from client-side JavaScript code.

You can use the AJAX Library to extend and customize the behavior of ASP.NET AJAX-enabled Web applications, but it is important to note that you don’t have to. You can go a long way without using any additional JavaScript in your applications, and only when you require more advanced functionality do you require any. If you do write additional client-side code, however, you will find that it is much easier with the functionality that the AJAX Library offers.

ASP.NET AJAX Control Toolkit

The AJAX Control Toolkit is a collection of additional server controls, including extender controls, that have been written by the ASP.NET AJAX community. Extender controls are controls that enable you to add functionality to an existing ASP.NET server control, typically by associating a client-side behavior with it. For example, one of the extenders in the AJAX Control Toolkit extends the TextBox control by placing “watermark” text in the TextBox, which appears when the user hasn’t yet added any content to the text box. This extender control is implemented in a server control called TextBoxWatermark. There are several other extender controls in the AJAX Control Toolkit, as well as a template and helper classes that you can use to create your own.

You can use the AJAX Control Toolkit to add quite a lot more functionality to your sites, beyond what is in the core download. These controls are also interesting simply to browse and will probably give you plenty of ideas about enhancing your Web applications. However, as the AJAX Control Toolkit is separate from the core download, you should not expect the same level of support for these controls.

ASP.NET 2.0 AJAX Futures CTP

The third and final download that is available from the ASP.NET AJAX Web site is the Futures CTP. This download is updated on a regular basis and contains additional client- and server-side functionality that may at some point become part of the core release. Some of this functionality is simply still in development; some was intended for the core release but was removed.

Tip 

Some of the functionality in the Futures CTP, such as XMLScript and remote Web service bridging, was part of the older “Atlas” releases of ASP.NET AJAX.

As with the AJAX Control Toolkit, you can use Futures CTP functionality to further enhance your applications, but you should use this component with a degree of caution, as its future is uncertain. Having said that, there are some extremely useful tools in this download, in particular for client-side JavaScript developers, who will find the additional UI and behavior classes in the Sys.Preview.UI namespace of interest.




Professional C# 2005 with .NET 3.0
Professional C# 2005 with .NET 3.0
ISBN: 470124725
EAN: N/A
Year: 2007
Pages: 427

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net