Chapter 1. ASP.NET AJAX, Ajax, and ASP.NET

This book is about ASP.NET AJAX (known in pre-release versions as “Atlas”), a collection of new Microsoft technologies that enables web developers—particularly ASP.NET 2.0 developers—to more easily create web sites with pages that use Ajax. Ajax-style pages provide a richer user interface. Such a page is also more responsive because it can respond immediately to users, and can interact more or less immediately with the server. ASP.NET AJAX also includes tools for creating mashups, web applications that combine content from multiple sites, typically using the APIs provided by third-party web services. We’ll be exploring all of these capabilities and more throughout the book. This chapter will get you started with ASP.NET AJAX while providing an overview of the underlying technology, and an architectural view of its operation.

ASP.NET AJAX and Ajax

ASP.NET AJAX expands on accepted browser technologies, including Asynchronous JavaScript and XML. Ajax has itself generated quite a lot of buzz lately (see the Preface for some thoughts about that), as it brings the functionality and user interface (UI) of web applications closer to that of desktop applications.

The main concept behind Ajax is to enable web pages to make HTTP requests in the background, or asynchronously, without reloading an entire page (or, in ASP.NET terms, without a round trip, or a postback). Ajax also allows more responsive UIs to be constructed by drawing on the power of commonly supported browser functions such as, JavaScript, Document Object Model (DOM), and Cascading Style Sheets (CSS). Google Suggest (http://www.google.com/webhp?complete=1&hl=en) demonstrates how an Ajax-enabled page can provide users with suggested words as text is entered (also known as auto-completion). Another example is Microsoft’s Virtual Earth (http://www.virtualearth.com/).

ASP.NET AJAX can help you create these types of Ajax-enabled applications by programming the browser (client). To work with the client side of Ajax and ASP.NET AJAX, you will need a solid understanding of the core Ajax technologies. Creating Ajax-enabled web pages by programming the browser requires knowledge of JavaScript, DOM, and the XMLHttpRequest object, which handles the requests from the client to the server. Additional knowledge of XML and XSLT is a plus, but is not mandatory. Neither is covered extensively in this book.)

Chapter 2 introduces JavaScript essentials. Other Ajax technologies are discussed in greater detail in Chapter 3. The example provided later in this chapter (”A First ASP.NET AJAX Example: Hello User“) will require only a basic understanding of the Ajax technologies. You will develop these skills as we move forward.

Writing Ajax-based applications without a framework like ASP.NET AJAX is not necessarily easy, and you can find yourself writing the same code over and over to perform tasks such as displaying the data returned from a request to the server, binding controls to data, or working with web services. You can also find yourself writing code to work around different browser implementations of the DOM. One of the goals of ASP.NET AJAX is to reduce or even eliminate the need for writing redundant and tedious code and to deliver a client-side developer experience that matches the experience of ASP.NET 2.0 developers. A related goal is to bring to JavaScript some of the productivity advantages of object-oriented programming (OOP) as well as a framework like .NET. ASP.NET AJAX includes client-script libraries that provide these advantages to the JavaScript/DOM/CSS programmer:

Browser compatibility layer

Allows ASP.NET AJAX scripts to run in most browsers and eliminates the need to handcraft scripts for each browser you want to target. (However, some browser-specific script is unavoidable, as you’ll see in Chapter 3.)

Core services

Provides JavaScript extensions that make OOP-like scripting possible, including support for classes, namespaces, event handling, inheritance, and object serialization with the formats JSON (JavaScript Object Notation) and XML. The most valuable of these extensions are discussed in Chapter 4.

Base class library

This library provides a number of .NET-like components, such as string builders and timers. You’ll learn about them in Chapter 4.

Script controls and components

Provides ASP.NET AJAX versions of standard HTML controls that are extended with capabilities like data binding, prepackaged behaviors (for example, drag-and-drop functionality), and tight integration with the ASP.NET AJAX client libraries. You can program these controls and components directly, or you can use a new declarative markup called xml-script, which we will discuss in several chapters throughout the book. If you are familiar with ASP.NET markup syntax, then you already understand (in general terms) the relationship of HTML controls, abstract programmable versions of these controls, and a declarative syntax.

ASP.NET AJAX and ASP.NET

Although ASP.NET AJAX provides a host of benefits to the client script programmer creating Ajax applications, it is not just about writing JavaScript and making asynchronous calls to the server. As ASP.NET AJAX was created by the ASP.NET team, it’s no surprise that one of its prominent features is a server framework that is integrated with (and requires) ASP.NET 2.0.

As with ASP.NET itself, ASP.NET AJAX is designed to deliver functionality—in this case, the benefits of Ajax—without requiring mastery of Ajax technologies. ASP.NET AJAX can manage Ajax functionality for you in much the same way that ASP.NET manages HTTP functionality, such as postbacks, state management, and the client script required to make ASP.NET all “just work.”

In addition, on the server side, ASP.NET AJAX works as part of ASP.NET, taking advantage of its inherent features. ASP.NET AJAX controls can interact with other ASP.NET controls and components and participate in the page life cycle. It can be linked to ASP.NET 2.0 features, such as sessions, authentication, and profiles, allowing you to take advantage of these types of capabilities on the client. Finally, with ASP.NET AJAX and ASP.NET, you can reach beyond the page to special web services.

Some of the key elements of the ASP.NET AJAX server framework are described here:

ASP.NET AJAX server controls

ASP.NET AJAX provides server-based controls resembling those of core ASP.NET 2.0, but which work with the ASP.NET AJAX client framework to deliver their functionality. Two controls in particular are fundamental to ASP.NET AJAX applications: ScriptManager, which will be discussed later in this chapter (see "The ScriptManager Control“), and UpdatePanel, which is discussed in Chapter 6.

ASP.NET AJAX ASP.NET services

Provide certain ASP.NET 2.0 application services that are directly available to ASP.NET AJAX client scripts, including profiles, personalization, authentication and membership, and culture-specific services. You can expect the number of ASP.NET services available to ASP.NET AJAX applications to grow with future releases of ASP.NET AJAX.

The Microsoft Ajax Library

This library provides a JavaScript-only library that does not depend on ASP.NET. Therefore, it can also be used without ASP.NET, as we will discuss in Chapter 22.

Ultimately, ASP.NET AJAX will take its rightful place as a key component of the next release of ASP.NET and will be fully supported with designers, IntelliSense, and debugging tools in a future release of Visual Studio.

ASP.NET AJAX Packages

The ASP.NET AJAX home page (http://ajax.asp.net/) presents several different packages that each have a specific focus:

ASP.NET AJAX Extensions

Also referred to as “ASP.NET AJAX Core,” this is the “main” ASP.NET AJAX package. It is fully supported by Microsoft and contains the ASP.NET AJAX infrastructure (covered in Part II).

ASP.NET AJAX Control Toolkit

This package contains an extensive collection of server-side components that provide astonishing Ajax functionality with very little effort. The Control Toolkit is an open source effort, although Microsoft still controls the project to ensure quality. However, there is no official Microsoft support for elements within the toolkit. Part III will explore the Control Toolkit.

ASP.NET AJAX Futures Release

This package provides a sneak peek at features that might become part of ASP.NET and ASP.NET AJAX (or not). The Future Release is also the home of less commonly used functionality that was originally part of pre-release versions of ASP.NET AJAX. The CTP (Community Technology Preview, a pre-release version made available for download) is refreshed more often than the core package. It also is not officially supported, so use it at your own risk. Part IV of this book covers the Futures Release that was current as of the time of printing, namely the ASP.NET Futures (July 2007) release. Also, as of May 2007, the ASP.NET AJAX Futures CTP is part of the ASP.NET Futures CTP, which includes fascinating new (and unsupported) possibilities for classic ASP.NET.

The Microsoft Ajax Library

The aforementioned JavaScript-only library, which will be covered in Part V.

Tip

In a somewhat surprising move, Microsoft provided the complete source code for ASP.NET AJAX. It can be downloaded from http://ajax.asp.net/.

This chapter will introduce and show you how to install the core ASP.NET AJAX Extensions (and will touch briefly on the Futures CTP), before Part II will get into more detail; the remaining packages will be introduced at the beginning of the respective parts.

ASP.NET AJAX Prerequisites and Installation

The best way to understand the power of ASP.NET AJAX is to use it. All you need to develop applications is a JavaScript-enabled browser on the client and an ASP.NET 2.0-enabled web server. A text editor is sufficient to get started. However, when applications get more complex, an IDE with additional features like IntelliSense, code completion, project management, debugging, and WYSIWYG functionality can be real timesavers. In the world of ASP.NET 2.0, the most widely used editor comes from Microsoft in the form of Visual Studio 2005.

Installing the IDE

The good news is that, although the full versions of Visual Studio 2005 are usually your best bet, the free web-centric Express edition of Visual Studio 2005—Microsoft Visual Web Developer 2005 Express Edition—also fully supports ASP.NET AJAX.

Tip

In the interest of simplicity, we will sometimes refer to Visual Web Developer as VWD throughout this book. By VWD we mean both the Express edition and the full version of Visual Studio 2005. The web development component of VS 2005 is also called Visual Web Developer (you can see it during installation of Visual Studio), so VWD is the most generic term for creating ASP.NET 2.0 applications with a Microsoft IDE.

If you do not already have an IDE, install either Visual Studio 2005 or Visual Web Developer Express Edition. For the latter, go to http://msdn.microsoft.com/vstudio/express/vwd/download, where you will find a web installer that not only downloads and installs VWD (Figure 1-1), but also takes care of installing the .NET Framework 2.0, if it is not already installed on your system.

Tip

If the web installer doesn’t work on your machine (e.g., it cannot connect to the Internet from within a corporate environment, or your connection is slow), you can find ISO and IMG images of a CD containing Visual Web Developer and all prerequisites (http://msdn.microsoft.com/vstudio/express/support/install), which you can download to a place with a better connection, then transfer onto a CD.

Installing Visual Web Developer Express Edition
Figure 1-1. Installing Visual Web Developer Express Edition

Installing ASP.NET AJAX

No matter which version of VWD you use, ASP.NET AJAX is integrated directly into the IDE. On the ASP.NET AJAX home page (http://ajax.asp.net), you can find a link to ASP.NET AJAX itself in the form of an MSI installer package named ASPAJAXExtSetup.msi. Look for the Microsoft ASP.NET 2.0 AJAX Extensions 1.0.

Before you launch the installer, uninstall any previous ASP.NET AJAX versions that may be on your system. The .msi installer asks only a few questions. Once you accept the ASP.NET AJAX license agreement, installation will begin, as shown in Figure 1-2.

Installing the template
Figure 1-2. Installing the template

When installation is complete, a new option for creating a web site—ASP.NET AJAX Web Site—will display within VWD and Visual Studio. This is the best way to get started with the ASP.NET AJAX technology as it copies all required files and places them in the proper directories (see Figure 1-3). It also installs the ASP.NET AJAX assembly in the Global Assembly Cache (GAC), so that it is automatically available for all ASP.NET applications.

After installation, you have a new web site template
Figure 1-3. After installation, you have a new web site template

ASP.NET AJAX also works with the upcoming Visual Studio 2008 and Visual Web Developer 2008 Express Edition. When creating a new web site, just state that you want to use .NET Framework 3.5 (see Figure 1-4), you don’t even have to install ASP.NET AJAX, since it comes with the .NET Framework 3.5. For .NET versions prior to 3.5, you still need to install ASP.NET AJAX separately. By the way, if you are working with both Visual Studio 2005 and Visual Studio 2008, or if you want to open ASP.NET AJAX projects in Visual Studio 2008 that were created in Visual Studio 2005, refer to "For Further Reading" at the end of this chapter for some important advice for these scenarios.

A .NET Framework 3.5 web site project automatically uses ASP.NET AJAX
Figure 1-4. A .NET Framework 3.5 web site project automatically uses ASP.NET AJAX

Tip

The ASP.NET AJAX web site offers further information and software related to ASP.NET AJAX. Some of the helpful items you will find on the site are detailed here:

  • Documentation that familiarizes you with several aspects of ASP.NET AJAX (ajax.asp.net/docs). The documentation also comes in a downloadable form that can be installed on your local computer (AspNet_AJAX_Documentation.zip).

  • ASP.NET AJAX samples

  • Links to other ASP.NET AJAX packages: The ASP.NET AJAX Control Toolkit, the Microsoft Ajax Library, the ASP.NET AJAX Futures release, and the ASP.NET AJAX source code.

Installing the Sample Database

Some of the examples in this book assume you are using SQL Server 2005 Express Edition as a database server (although the examples can also be adapted to other data sources). However, if you already have Microsoft SQL Server installed on your computer, you can use that as well. If you do not have Microsoft SQL Server available, download and install SQL Server Express (a free download).

To make the setup as easy to deploy as possible, I use the Microsoft sample database AdventureWorks for all of the database examples in this book. I also assume that AdventureWorks was installed into a local SQL Server 2005 Express Edition installation, and is accessible using Windows authentication, at (local)\SQLEXPRESS.

Tip

You may need to adapt the SQL Express pathname to your local system.

Depending on the version of SQL Server you use, AdventureWorks is available for download at either of the following locations:

Select the appropriate link, download and run the installer. When installation is complete, you will have to attach the AdventureWorks_Data.mdf file (residing in your SQL Server’s Data folder) to your SQL Server 2005 installation. The most convenient way to do is by using Microsoft SQL Server Management Studio Express (SSMSE), a free GUI I recommend for administering SQL Server 2005 Express Edition installations. SSMSE is available in both 32-bit and 64-bit versions at http://www.microsoft.com/downloads/details.aspx?familyid=c243a5ae-4bd1-4e3d-94b8-5a0f62bf7796&displaylang=en.

After you’ve finished installing and configuring AdventureWorks, go to the Windows Start menu and launch SQL Server on your system. Enter the information for your SQL Server 2005 Express Edition installation in the dialog box shown in Figure 1-5. The default installation can be accessed using the server name (local)\SQLEXPRESS or YourMachineName\SQLEXPRESS and authentication type Windows Authentication.

The SSMSE login window
Figure 1-5. The SSMSE login window

Next, right-click on the databases folder within SSMSE and select Attach. In the dialog box that opens (Figure 1-6), click the Add button and select the AdventureWorks_Data.mdf file. Click OK twice. The AdventureWorks database is now permanently attached to your installation of SQL Server 2005 Express Edition.

Attaching the MDF file to the SQL Server 2005 Express Edition installation
Figure 1-6. Attaching the MDF file to the SQL Server 2005 Express Edition installation

ASP.NET AJAX Structure and Architecture

It is now time to actually use ASP.NET AJAX. Start VWD and create a new ASP.NET web site using the ASP.NET AJAX template. If you take a look at Solution Explorer, you will see a regular ASP.NET web site. Don’t be surprised; the installer placed the ASP.NET AJAX assembly directly in the GAC. The only thing different about it is the file, Web.config, which is preconfigured with the settings required for ASP.NET AJAX to work.

ASP.NET AJAX consists of both server and client components. It is possible to use only the server components, or only the client components. There is one exception: every ASP.NET AJAX application will need the ScriptManager server control, which will be discussed later in this chapter. Usually, you will want to use both the server and client components.

The roles the client and server components play in an ASP.NET AJAX project will become clearer when we take a closer look at how Ajax applications that use XMLHttpRequest really work.

Figure 1-7 shows the basic structure of ASP.NET AJAX. Whereas standard web pages consist of only two parts—one request and one response—Ajax-enabled web pages can continuously exchange data with the server. ASP.NET AJAX helps on both ends of the wire. Client script libraries (which, as you will soon see are dynamically loaded by the ScriptManager control) facilitate communication between browser and web server and make client coding easier. The code implemented in the ASP.NET AJAX server assembly takes care of accepting and handling XMLHttpRequest calls and also implements some convenient server web controls that we will cover later in the book. As a result, client and server components can exchange data with very little effort by the programmer.

The life cycle of an ASP.NET AJAX web page
Figure 1-7. The life cycle of an ASP.NET AJAX web page

The ASP.NET AJAX client framework (bottom layer of the client component in Figure 1-7) is sent to the browser from the server the first time an ASP.NET AJAX-enabled page is requested (steps 1 and 2 in Figure 1-7). Subsequent requests to the server from the same page in an Ajax application can then be made with HTTP requests that return text and XML (steps 3 and 4 in Figure 1-7). An ASP.NET web page might use full-page postbacks and asynchronous requests for different tasks.

The individual components of ASP.NET AJAX, both on the client and on the server, are detailed throughout the book. However you should always keep the basic structure in mind, including the data exchange between client and server. The smaller the number of page requests, the better—at least for the purpose of avoiding page refreshes.

A First ASP.NET AJAX Example: Hello User

To test whether your setup of ASP.NET AJAX has been successful and to see the framework in action, let’s end this chapter by creating a small sample application. The sample page accepts a username, sends it to the web server (in the background, using XMLHttpRequest), and receives it back with some extra text. The new version of the name is then presented to the user. This sample is a simple demonstrations of how easy it can be to set up an application using the features of ASP.NET AJAX. In later chapters, more detailed descriptions of the inner workings and operation will be provided.

In VWD, create a new web site using the ASP.NET AJAX template. Next, create a new web service (using the web service file template) in the root directory of the web site and call it WebService.asmx. In the web service .asmx file, implement a simple web method that accepts one string parameter by pasting the code shown in Example 1-1 into the file. Notice that you need the attribute, [ScriptServices], which is actually defined by ASP.NET AJAX (within the namespace System.Web.Script.Services).

Example 1-1. The web service
WebService.asmx

<%@ WebService Language="C#" Class="WebService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://hauser-wenz.de/AspNetAJAX/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService  : System.Web.Services.WebService {
    [WebMethod]
    public string sayHello(string name) {
    return "Hello " + name + ", says the server!";
    }
}

Now call this web service in your web browser, but append /js to the URL. As shown in Figure 1-8, this URL actually returns JavaScript code. In fact, this code implements a JavaScript proxy class (to be covered in more detail in Chapter 5). Most important, the code produces a variable named WebService that provides a reference to the web service.

ASP.NET AJAX creates this JavaScript code automatically
Figure 1-8. ASP.NET AJAX creates this JavaScript code automatically

You will see that the ASP.NET AJAX template already created a file, Default.aspx, with some contents that you will expand in the following steps. Following is the code you will see in this file:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
        </div>
    </form>
</body>
</html>

The first thing you will likely notice is a new control: <asp:ScriptManager>. This control is the central element of every ASP.NET AJAX web page. We will explore ScriptManager control in greater detail later in this chapter (see "The ScriptManager Control“).

Be sure the Default.aspx file is still open in the editor and reference the web service in the following fashion within the ScriptManager element. When the page runs, this reference will generate a JavaScript proxy so that your page can use the code generated dynamically by the web service code:

<asp:ScriptManager ID="ScriptManager1" runat="server">
  <Services>
    <asp:ServiceReference Path="WebService.asmx" />
  </Services>
</asp:ScriptManager>

At this point, you need to bring in some HTML elements. Add a text box and an HTML button to the existing <form> element (within the <div> element, if you want to adhere to XHTML standards):

<input type="text" id="name" name="name" />
<input type="button" value="Call Service" onclick="callService(this.form);" />

The onclick event handler of the button calls a custom JavaScript function named callService( ) and passes a reference to the current form. The callService( ) method is where the web service is invoked. To call the web service’s sayHello( ) method, the code can use the JavaScript proxy object, which is exposed via an automatically generated variable named WebService. (The name WebService matches the name of the web service class you created earlier.)

The sayHello( ) method expects not only a string, but also references to up to three handler functions; one to call when the web service succeeds (callComplete), one to call when an error occurs (callError), and a third to call if the call times out. (For this example, we’ll use only the first two.)

Next, place the following code within a client-side <script> element on your page:

function callService(f) {
  WebService.sayHello(
    f.elements["name"].value,
    callComplete,
    callError);
}

Finally, you need to provide the two handler functions for the callComplete and callError events. To do this, add the following code to the client script block that you just created:

function callComplete(result) {
  window.alert(result);
}
function callError(result) {
  window.alert("Error! " + result);
}

Example 1-2 shows the complete code for the Default.aspx file.

Example 1-2. A simple ASP.NET AJAX page that calls a web service
Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>ASP.NET AJAX</title>

  <script language="Javascript" type="text/javascript">
  function callService(f) {
    WebService.sayHello(
      f.elements["name"].value,
      callComplete,
      callError);
  }

  function callComplete(result) {
    window.alert(result);
  }

  function callError(result) {
    window.alert("Error! " + result);
  }
  </script>

</head>
<body>
  <form id="form1" runat="server">
    <asp:ScriptManager
 ID="ScriptManager1"
runat="server">
      <Services>
        <asp:ServiceReference Path="WebService.asmx" />
      </Services>
    </asp:ScriptManager>
    <div>
      <input type="text" id="name" name="name" />
      <input type="button" value="Call Service" onclick="callService(this.form);" />
    </div>
  </form>

</body>
</html>

Figure 1-9 shows the results when the page is loaded and the Call Service button is clicked.

The application works as expected
Figure 1-9. The application works as expected

Run the page (F5, or Ctrl+F5 in VWD). As you can see in the browser, the results are predictable—not only with Internet Explorer, but also with other relevant browsers. Click the Call Service button several times, and note carefully that the button does not result in a postback, even though the page is communicating with the web service on the server.

The ScriptManager Control

Now that you’ve completed the first exercise, here is some more background information about how it worked, and how the other ASP.NET AJAX examples throughout this book work.

The central element of an ASP.NET AJAX-powered ASP.NET page is the ScriptManager control. This control takes care of loading the required JavaScript libraries for ASP.NET AJAX.

If you run an ASP.NET AJAX application and then examine the resulting source code in the browser, you will see that the code has changed quite a bit from what it looked like when you were editing it. The <asp:ScriptManager> element will have been replaced with the following code (although the undecipherable data contained in the URL will be different on your system):

<script src="/AJAXEnabledWebSite1/WebResource.axd?d=Jd4j-uCaCWzJ5gY8Rtbjnw2
&amp;t=632962478475625000" type="text/javascript"></script>

<script src="/AJAXEnabledWebSite1/ScriptResource.axd?d=4vKPTV3rK3vcGz1fNEcIXI-
FjnEGgHGMpqfUlmBk4NA5KxnrqcWXFT6hln9QkTuglOUzzonzRPSF5F3_-
0aWhWOb3FCqEciv4AZjgqdK5us1&amp;t=633074690770156250"
type="text/javascript"></script>
<script src="/AJAXEnabledWebSite1/ScriptResource.axd?d=4vKPTV3rK3vcGz1
fNEcIXI-FjnEGgHGMpqfUlmBk4NA5KxnrqcWXFT6hln9QkTuglOUzzonzRPSF5F3_
-0aWhdU1qTQPzcChFvbHT6FrI-81&amp;t=633074690770156250"
type="text/javascript"></script>

ASP.NET AJAX also generated JavaScript code that initializes some parts of the Ajax framework for you.

Tip

When building the web application in debug mode, the JavaScript code created by ASP.NET is nicely formatted and some errors are caught. This is convenient for developing purposes, but is not required (in fact, is recommended against) when the web site is deployed, since it makes the JavaScript code and therefore the page’s size larger.

This ScriptManager element must be present on all pages that use ASP.NET AJAX features.

If you are using ASP.NET 2.0 master pages and most of your pages use the ASP.NET AJAX framework, you might consider putting the ScriptManager control on your master page instead of on the individual pages. However, this can cause difficulties when you need to reference additional JavaScript files or web services (like the “Hello User” example earlier) on a content page. Only one ScriptManager control is allowed per page, so you would need to reference the JavaScript file or web service on every page that use ASP.NET AJAX features, even on those that do not need these external resources.

For this scenario, ASP.NET AJAX provides the ScriptManagerProxy control. This control provides ScriptManager functionality when there is already another ScriptManager present.

<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
  <Scripts>
    <asp:ScriptReference Path="MyScript.js" />
  </Scripts>
</asp:ScriptManagerProxy>

The ScriptManagerProxy control can also be useful if you are creating an ASP.NET user control that includes AJAX functionality in cases where there is a ScriptManager control on the host page.

This was just the first step. There’s much more to come in the following chapters!

Summary

This chapter introduced ASP.NET AJAX, explained its relationship to Ajax and ASP.NET 2.0, and guided you through its installation and the installation of other software you need for this book, including the AdventureWorks database. You also created your first working ASP.NET AJAX example and learned about the ScriptManager control, one of two key server controls that ship with ASP.NET AJAX. In the next chapter, you’ll have a look at the JavaScript you will need to work with ASP.NET AJAX.

For Further Reading

http://ajax.asp.net/

ASP.NET AJAX home page

http://ajax.asp.net/downloads/default.aspx?tabid=47

ASP.NET AJAX downloads

http://ajax.asp.net/docs/installingaspnetajax.aspx

ASP.NET AJAX installation instructions in the Microsoft documentation

http://blogs.msdn.com/webdevtools/archive/2007/07/28/upgrading-asp-net-ajax-1-0-websites-and-web-applications-to-net-framework-3-5.aspx

Important information for upgrading ASP.NET AJAX web sites created with Visual Studio 2005 to Visual Studio 2008/.NET Framework 3.5

http://weblogs.asp.net/scottgu/archive/2007/08/04/fixes-for-common-vs-2008-and-net-3-5-beta2-issues.aspx

A list of some known issues in Visual Studio 2008 Beta 2 and their possible workarounds

Get Programming ASP.NET AJAX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.