Home / AJAX

ASP.NET Ajax Overview

Modified on 2009/12/17 21:54 by Erik Reitan Categorized as Uncategorized
The ASP.NET Ajax Library is a JavaScript library that enables you to build database-driven web applications that execute entirely within a web browser. The ASP.NET Ajax Library is compatible with all modern web browsers including Internet Explorer 6+, Google Chrome, Opera, Apple Safari, and Mozilla Firefox.

The ASP.NET Ajax Library includes the Ajax Control Toolkit. The Ajax Control Toolkit is a rich set of 40 client controls that includes controls for creating auto-complete textboxes, modal popups, calendars, collapsible panels, and masked edit textboxes. You can use all of the Ajax Control Toolkit controls within an ASP.NET Web Forms application by dragging and dropping the controls from the Visual Studio toolbox. You can use the majority of the controls within an ASP.NET MVC application or even a pure HTML application.

The ASP.NET Ajax Library was designed to work seamlessly with jQuery. All of the ASP.NET Ajax Library controls are exposed as jQuery plug-ins automatically.

When you build a Microsoft Ajax application, you provide your users with a richer and more responsive user experience. Microsoft 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 Microsoft Ajax features, you can improve the user experience and the efficiency of your Web applications. You can use the Microsoft Ajax Library to create pure Ajax applications or you can use Microsoft Ajax to enhance WebForms based applications, such as ASP.NET Web applications or ASP.NET MVC applications. Note The Microsoft Ajax Library is a JavaScript framework for building client-side Web applications. The latest version of the Microsoft Ajax Library is released separately from the ASP.NET framework and Visual Studio. You can download the latest version of the Microsoft Ajax Library by visiting the www.ASP.net/ajax website. The content in this topic focuses on enhancing WebForms based applications.

Why Use the Microsoft Ajax Library?

Ajax features enable you to build rich Web applications that have many advantages over Web applications that are completely server-based. Ajax-enabled applications offer:
  • Complete client side processing for Ajax applications, where the client-script libraries can be included without using server-side technology.
  • Familiar UI elements such as progress indicators, tooltips, and pop-up windows.
  • Improved efficiency for WebForms based applications, because all or significant parts of a Web page's processing can be performed in the browser.
  • Partial-page updates for WebForms based application 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 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 Microsoft Ajax

Features The architecture of a Microsoft Ajax Web application consists of either a client only solution or a client and server solution. A client only solution consists of using the Microsoft Ajax Library without using ASP.NET server controls. For instance, an .html page could include script tags that include the Microsoft Ajax Library script files. The Microsoft Ajax Library allows the Ajax applications to perform all processing on the client. A client and server solution consists of using both the Microsoft Ajax Library and ASP.NET server controls. Microsoft Ajax Library The Microsoft Ajax Library contains script files that encompass Ajax functionality for creating pure Ajax applications. The Microsoft Ajax Library is released separately from the ASP.NET framework or Visual Studio. You can download the latest version of the Microsoft Ajax Library by visiting the www.ASP.net/ajax website. The Microsoft Ajax Library consists of release and debug versions of the following script resources:
  • MicrosoftAjax.js
  • MicrosoftAjaxTemplates.js
  • MicrosoftAjaxAdoNet.js
  • MicrosoftAjaxDataContext.js

To use the features in a Web page, you must first enable Microsoft Ajax on the page and include the client script libraries that you want to use. This is done either by using script tags or by including a server-side ScriptManager control in the page under which you add one or more ScriptReference controls. You can then include the optional script files for specific functionality:
  • MicrosoftAjaxTemplates.js (or MicrosoftAjaxTemplates.debug.js)
  • MicrosoftAjaxAdoNet.js (or MicrosoftAjaxAdoNet.debug.js)
  • MicrosoftAjaxDataContext.js (or MicrosoftAjaxDataContext.debug.js)

You can reference the Microsoft Ajax Library that is included either directly in the project from script files or from the Microsoft Ajax Content Delivery Network (CDN).

The following example shows how to reference the static Microsoft Ajax scripts libraries using script tags when you have downloaded the separate Microsoft Ajax client script libraries and included them in the scripts directory within the project:
<script type="text/javascript" src="../scripts/MicrosoftAjax.debug.js"></script>
<script type="text/javascript" src="../scripts/MicrosoftAjaxTemplates.debug.js"></script>
<script type="text/javascript" src="../scripts/MicrosoftAjaxAdoNet.debug.js"></script>
<script type="text/javascript" src="../scripts/MicrosoftAjaxDataContext.debug.js"></script>

The following example shows how to reference Microsoft Ajax client script libraries using the Microsoft Ajax Content Delivery Network (CDN):
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/beta/0911/MicrosoftAjax.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/beta/0911/MicrosoftAjaxTemplates.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/beta/0911/MicrosoftAjaxAdoNet.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/beta/0911/MicrosoftAjaxDataContext.js"></script>

When using Visual Studio 2010, the following example illustrates how to use the ScriptManager control to include the Microsoft Ajax client script libraries automatically using the Microsoft Ajax Content Delivery Network (CDN):
<asp:ScriptManager ID="ScriptManager1" EnableCdn="true" runat="server">

When using either Visual Studio 2008 or Visual Studio 2010, the following example shows how to reference the static scripts using the ScriptManager control. In this example, the client script libraries have been downloaded and included in the scripts directory within a project:
<asp:ScriptManager ID="sm" runat="server">
        <asp:ScriptReference Name="MicrosoftAjax.js" Path="~/scripts/MicrosoftAjax.js" />
        <asp:ScriptReference ScriptMode="Inherit" Path="~/scripts/MicrosoftAjaxTemplates.js" />
        <asp:ScriptReference ScriptMode="Inherit" Path="~/scripts/MicrosoftAjaxAdoNet.js" />
        <asp:ScriptReference ScriptMode="Inherit" Path="~/scripts/MicrosoftAjaxDataContext.js" />

The MicrosoftAjaxTemplates.js file includes the template-rendering engine and template related classes. The MicrosoftAjaxAdoNet.js file includes classes that are specific to ADO.NET data services, such as the AdoNetServiceProxy class. The MicrosoftAjaxDataContext.js file includes facilities for read-write scenarios. Therefore, to use all features of the Microsoft Ajax Library, you would need to include all four script files.

The ASP.NET ScriptManager includes the ability to use only parts of the Microsoft Ajax framework for efficiency, as well as the ability to not include the Microsoft Ajax Library at all. The ScriptManager control provides services such as centralized management of references, support for debug and release modes, support for localization, script combining, and Content Delivery Network (CDN) support. These services can be useful to all client-script developers, even those who use JavaScript libraries other than Microsoft AJAX, such as jQuery.

In Microsoft Ajax, the default behavior for the ScriptManager control is to include the complete Microsoft Ajax Library. However, the ScriptManager control supports a MicrosoftAjaxMode property that lets you choose a subset of the framework by using only portions of the library in the form of split script files. The MicrosoftAjaxMode property can have one of the following values:
  • Enabled — All Microsoft AJAX scripts are included (legacy behavior). This is the default value of the property.
  • Explicit — Each split script file must be added explicitly; it is up to you to make sure that you include all scripts that have dependencies on one another.
  • Disabled — All Microsoft Ajax script features are disabled and the ScriptManager control does not reference any scripts automatically.

For more information about split script files, see Reducing the Download Size of the Microsoft AJAX Library.