Freigeben über


ASP.NET AJAX Overview

AJAX features in ASP.NET enable you to quickly create Web pages that include a rich user experience with responsive and familiar user interface (UI) elements. AJAX features include client-script libraries that incorporate cross-browser ECMAScript (JavaScript) and dynamic HTML (DHTML) technologies, and integration with the ASP.NET server-based development platform. By using AJAX features, you can improve the user experience and the efficiency of your Web applications.

Why Use ASP.NET AJAX Features?

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.

Architecture of AJAX Features in ASP.NET

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.

Note

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.

ASP.NET AJAX client and server architecture

ASP.NET AJAX Server and Client Architecture

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.

AJAX Client Architecture

The client architecture includes libraries for component support, browser compatibility, networking, and core services.

Components

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.

Browser Compatibility

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.

Networking

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.

Core Services

The AJAX client-script libraries in ASP.NET consist of JavaScript (.js) files that provide features for object-oriented development. The object-oriented features included in the ASP.NET AJAX client-script libraries enable a high level of consistency and modularity in client scripting. The following core services are part of the client architecture:

  • Object-oriented extensions to JavaScript, such as classes, namespaces, event handling, inheritance, data types, and object serialization.

  • A base class library, which includes components such as string builders and extended error handling.

  • Support for JavaScript libraries that are either embedded in an assembly or are provided as standalone JavaScript (.js) files. Embedding JavaScript libraries in an assembly can make it easier to deploy applications and can help solve versioning issues.

  • 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.

Globalization

The AJAX server and client architecture in ASP.NET provides a model for localizing and globalizing client script. This enables you to design applications that use a single code base to provide UI for many locales (languages and cultures). For example, the AJAX architecture enables JavaScript code to format Date or Number objects automatically according to culture settings of the user's browser, without requiring a postback to the server. For more information, see Walkthrough: Globalizing a Date by Using Client Script

AJAX Server Architecture

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.

Script Support

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:

Localization

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:

Web Services

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

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.

Server Controls

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.

  • ScriptManager
    Manages script resources for client components, partial-page rendering, localization, globalization, and custom user scripts. The ScriptManager control is required in order to use the UpdatePanel, UpdateProgress, and Timer controls.

  • UpdatePanel
    Enables you to refresh selected parts of the page, instead of refreshing the whole page by using a synchronous postback.

  • UpdateProgress
    Provides status information about partial-page updates in UpdatePanel controls.

  • Timer
    Performs postbacks at defined intervals. You can use the Timer control to post the whole page, or use it together with the UpdatePanel control to perform partial-page updates at a defined interval.

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.

AJAX Control Toolkit

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.

AJAX Community-supported Futures Releases

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.

See Also

Concepts

Browser Security Settings for AJAX Enabled ASP.NET Pages

Adding AJAX Functionality to ASP.NET Controls

AJAX Client Life-Cycle Events