|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
ASP.NET AJAX Overview
AJAX features in ASP.NET enable you to build rich Web applications that have many advantages over Web applications that are completely server-based. AJAX-enabled applications offer:
Improved efficiency, because significant parts of a Web page's processing are performed in the browser.
Familiar UI elements such as progress indicators, tooltips, and pop-up windows.
Partial-page updates that refresh only the parts of the Web page that have changed.
Client integration with ASP.NET application services for forms authentication, roles, and user profiles.
Auto-generated proxy classes that simplify calling Web service methods from client script.
A framework that lets you customize of server controls to include client capabilities.
Support for the most popular and generally used browsers, which includes Microsoft Internet Explorer, Mozilla Firefox, and Apple Safari.
The architecture of AJAX features in ASP.NET consists of two pieces: client-script libraries and server components. These pieces are integrated to provide a robust development framework.
In addition to the AJAX features in ASP.NET, you can use the ASP.NET AJAX Control Toolkit and the features in the Microsoft ASP.NET Futures releases, which are both community supported.
The following illustration shows the functionality that is included in the client-script libraries and server components.
The illustration shows the functionality of the client-based Microsoft AJAX Library, which includes support for creating client components, browser compatibility, and networking and core services. The illustration also shows the functionality of server-based AJAX features, which include script support, Web services, application services, and server controls. The following sections describe the illustration in more detail.
The client architecture includes libraries for component support, browser compatibility, networking, and core services.
Client components enable rich behaviors in the browser without postbacks. Components fall into three categories:
Components, which are non-visual objects that encapsulate code, such as a timer object.
Behaviors, which extend the basic behavior of existing DOM elements.
Controls, which represent a new DOM element that has custom behavior.
The type of component that you use depends on the type of client behavior you want. For example, a watermark for an existing text box can be created by using a behavior that is attached to the text box. For more information, see Creating Client Components and Controls.
The browser compatibility layer provides AJAX scripting compatibility for the most frequently used browsers (including Microsoft Internet Explorer, Mozilla Firefox, and Apple Safari). This enables you to write the same script regardless of which supported browser you are targeting. For more information, see Browser Security Settings for AJAX Enabled ASP.NET Pages.
The networking layer handles communication between script in the browser and Web-based services and applications. It also manages asynchronous remote method calls. In many common scenarios, such as partial-page updates that use the UpdatePanel control, the networking layer is used automatically and does not require that you write any code.
The networking layer also provides support for accessing server-based forms authentication, role information, and profile information in client script. This support is also available to Web applications that are not created by using ASP.NET, as long as the application has access to the Microsoft AJAX Library. For more information, see Web Services in ASP.NET AJAX.
A base class library, which includes components such as string builders and extended error handling.
For more information, see Creating Custom Client Script by Using the Microsoft AJAX Library.
Debugging and Error Handling
The core services include the Sys.Debug class, which provides methods for displaying objects in readable form at the end of a Web page. The class also shows trace messages, enables you to use assertions, and lets you break into the debugger. An extended Error object API provides helpful exception details with support for release and debug modes. For more information, see Debugging and Tracing AJAX Applications Overview.
The server pieces that support AJAX development consist of ASP.NET Web server controls and components that manage the UI and flow of an application. The server pieces also manage serialization, validation, control extensibility, and so on. There are also ASP.NET Web services that enable you to access ASP.NET application services for forms authentication, roles, and user profiles.
AJAX features in ASP.NET are implemented by using supporting scripts that are sent from the server to the client. Depending on what AJAX features that you enable, different scripts are sent to the browser.
You can also create custom client script for your ASP.NET applications. In that case, you can also use AJAX features to manage your custom script as static .js files (on disk) or as .js files embedded as resources in an assembly.
ASP.NET AJAX features include a model for release and debug modes. Release mode provides error checking and exception handling that is optimized for performance, with minimized script size. Debug mode provides more robust debugging features, such as type and argument checking. ASP.NET runs the debug versions when the application is in debug mode. This enables you to throw exceptions in debug scripts while minimizing the size of release code.
Script support for AJAX in ASP.NET is used to provide two important features:
Partial-page rendering, which updates regions of the page by using an asynchronous postback. For more information, see Partial-Page Rendering Overview.
The ASP.NET AJAX architecture builds on the foundation of the ASP.NET 2.0 localization model. It provides additional support for localized .js files that are embedded in an assembly or that are provided on disk. ASP.NET can serve localized client scripts and resources automatically for specific languages and regions.
For more information, see the following topics:
With AJAX functionality in an ASP.NET Web page, you can use client script to call both ASP.NET Web services (.asmx) and Windows Communication Foundation (WCF) services (.svc). The required script references are automatically added to the page, and they in turn automatically generate the Web service proxy classes that you use from client script to call the Web service.
You can also access ASP.NET Web services without using ASP.NET AJAX server controls (for example, if you are using a different Web development environment). To do so, in the page you can manually include references to the Microsoft AJAX Library, to script files, and to the Web service itself. At run time, ASP.NET generates the proxy classes that you can use to call the services. For more information, see Web Services in ASP.NET AJAX.
Application services in ASP.NET are built-in Web services that are based on ASP.NET forms authentication, roles, and user profiles. These services can be called by client script in an AJAX-enabled Web page, by a Windows client application, or by a WCF-compatible client. For information and examples, see. Using ASP.NET Web Services.
ASP.NET AJAX server controls consist of server and client code that integrate to produce rich client behavior. When you add an AJAX control to an ASP.NET Web page, the page automatically sends supporting client script to the browser for AJAX functionality. You can provide additional client code to customize the functionality of a control, but this is not required.
The following list describes the most frequently used ASP.NET AJAX server controls.
You can also create custom ASP.NET server controls that include AJAX client behaviors. Custom controls that enhance the capabilities of other ASP.NET Web controls are referred to as extender controls. For more information, see Adding AJAX Functionality to ASP.NET Controls and ASP.NET AJAX Extender Controls Overview.
The ASP.NET AJAX Control Toolkit is a collection of samples and components that show you some of the experiences you can create with ASP.NET AJAX controls and extenders. The Control Toolkit provides samples and a powerful SDK to make it simple to create and reuse custom controls and extenders. You can download the ASP.NET AJAX Control Toolkit from the ASP.NET Ajax Web site. The ASP.NET AJAX Control Toolkit is community supported.
The ASP.NET AJAX community-supported Futures releases provide features that extend the AJAX capabilities of ASP.NET with functionality that remains under development and that is not included in ASP.NET. This includes additional extender controls, support for client declarative syntax (xml-script), and more. To download and learn more about the Futures release, see the ASP.NET AJAX Web site.