• No results found

Ajax stands for Asynchronous JavaScript and XML and has been around for quite a long time. Ajax is a set of technologies that enables parts of a page to communicate directly to the server. If needed, communication can be performed asynchronously. Ajax uses a mixture of DHTML, JavaScript, and XMLHTTP to enrich the browser user interface experience.

Ajax-style applications really shine when you need to perform actions that take a long time to complete and you do not want to force the end user to wait. Typical examples are complex calculations, data retrieval over slow remote connections, retrieval of huge amounts of infor- mation, or data retrieval from multiple remote resources. Ajax is also great for server polling scenarios, where you continually refresh parts of a page with the latest information. Ajax’s rich interaction comes close to that in Windows applications.

During the last year or so Ajax has become quite popular. One reason is because nowadays all popular browsers (such as Internet Explorer and Firefox) support a programmable document object model (DOM) and the latest versions of them offer the capability to communicate directly between client and server, without requiring a complete page postback.

36 C H A P T E R 2 ■ U S I N G A J A X A N D A T L A S I N W E B P A R T S

Another reason has to do with the maturity level of Ajax-style development. In its infancy, Ajax-style development included a lot of manual work. The same was true for server-side web development. ASP.NET solved many of the complexities involved in developing the server side of web applications. Now, modern Ajax frameworks such as Atlas solve many of the complexities of the client side of web development.

The result of Ajax-style development is a new generation of web applications that are responsive and interactive and provide advanced user interfaces and are capable of processing data in real time.

Creating Ajax-style applications is not simple because you have to understand the different object models each browser has to offer. Browser compatibility issues can be a real hassle when doing client-side development. Another disadvantage is that a significant amount of the development work is spent in creating JavaScript script libraries. JavaScript is object-based instead of object-oriented and is type-unsafe. The JavaScript development experience does not compare to doing ASP.NET server-based development.

Atlas tries to solve these problems and is the logical next step in the evolution of Ajax-style applications. Atlas is a framework built on top of .NET 2.0 that allows developers to create Ajax- style applications combining client script libraries with the ASP.NET 2.0 server-based development framework. Atlas makes it easy to add rich client-side behavior to ASP.NET 2.0 web applications. Atlas offers a set of object-oriented application programming interfaces (APIs) making JavaScript development easier. Atlas offers cross-browser compatibility. Atlas can be programmed via a declarative model for client development without creating a line of code. The declarative model offers a development experience that is very similar to using ASP.NET server controls. Atlas offers web server controls that automatically emit all the client script needed for Atlas applications. Finally, Atlas offers integrated Visual Studio .NET 2005 development tools for client-side devel- opment, offering features such as debugging and statement completion.

The focus of Atlas is broader than Ajax. Ajax focuses on asynchronous communication with the server. Atlas is very capable of taking care of that, but Atlas goes a step further. Atlas tries to make client-side development easier, letting you create advanced user interfaces. The Atlas control toolkit (found at http://atlas.asp.net) offers a set of controls that are very easy to use and would require advanced JavaScript coding to implement yourself. At the time of this writing, the toolkit (version 1.0.60504.0) contained the following controls:

Cascading Drop-Down: This is a drop-down list that can be populated via web services. Collapsible Panel: This control lets you create collapsible sections within a web page. Confirm Button: This catches a button click and displays a new message window to the user. DragPanel: This control lets you define page sections that can be dragged around the page. Hover Menu: This control will let you associate a control with a pop-up panel to display

additional content.

PopupControl: This control can be attached to any control to open a pop-up window that

displays additional content.

Reorder List: This implements a bulleted databound list with items that can be reordered

interactively.

C H A P T E R 2 ■ U S I N G A J A X A N D A T L A S I N W E B P A R T S 37

Text Box Watermark: This can be attached to an ASP.NET text box control to get water-

mark behavior. This lets you display a default message in a text box (for example, Type First Name Here) that goes away once the user has typed some text into the text box.

Toggle Button: This can be attached to the ASP.NET check box control to enable the use of

custom images to show the state of the check box.

This chapter focuses on the Ajax part of Atlas, not on the Atlas controls. Nevertheless, we want to whet your appetite for using the Atlas controls a little bit by showing some screenshots of them. Figure 2-1 shows the DragPanel control.

Figure 2-1. The DragPanel control

Figure 2-2 shows the Hover Menu control.

Figure 2-2. The Hover Menu control

Figure 2-3 shows the PopupControl.

38 C H A P T E R 2 ■ U S I N G A J A X A N D A T L A S I N W E B P A R T S

Figure 2-3. The PopupControl

Figure 2-4 shows the Reorder List control.

Figure 2-4. The Reorder List control

Figure 2-5 shows the Text Box Watermark control.

Figure 2-5. The Text Box Watermark control

Figure 2-6 shows the Toggle Button control.

C H A P T E R 2 ■ U S I N G A J A X A N D A T L A S I N W E B P A R T S 39

Figure 2-6. The Toggle Button control

Ajax Frameworks for ASP.NET

As a testament to the popularity of Ajax, if you search for it on the Internet, you will probably find a couple dozen Ajax implementations. There are Ajax frameworks written in JavaScript, C++, Java, ColdFusion, Lisp, Perl, PHP, Python, and the list goes on. Even if you limit the search to .NET frameworks, you will find more than ten of them. The following list provides an over- view of the well-known Ajax frameworks that are targeted toward ASP.NET:

Atlas: The first Ajax framework for ASP.NET is Atlas. Atlas is created by Microsoft. Atlas

integrates an extensive set of client script libraries with the rich, server-based development platform of ASP.NET 2.0. At the time of this writing Atlas was not released officially; it was still in the Community Technology Preview (CTP) phase. Atlas only supports ASP.NET 2.0. More information can be found at http://atlas.asp.net.

ComfortASP.NET: Internally, ComfortASP.NET uses a mixture of DHTML, JavaScript, and

XMLHTTP. The developer only implements pure server-side ASP.NET. ComfortASP.NET supports ASP.NET 1.1 and ASP.NET 2.0. ComfortASP.NET reduces HTML traffic. More information can be found at http://www.comfortasp.de/.

MagicAjax.NET: MagicAjax.NET is an open source framework that lets you put Ajax-enabled

controls on a web page within an Ajax panel. MagicAjax.NET does not require you to write any JavaScript. MagicAjax.NET supports ASP.NET 1.1 and ASP.NET 2.0. More information can be found at http://www.magicajax.net.

ZumiPage: ZumiPage is a commercial framework that requires no code changes to existing

projects. ZumiPage supports ASP.NET 1.1 and ASP.NET 2.0. More information can be found at http://www.zumipage.com.

Outpost: Outpost is a free framework that gets the HTML of page controls that were changed

and transports the changes automatically to the client in a hidden postback. Outpost supports ASP.NET 1.1 and ASP.NET 2.0. More information can be found at http://csharpedge. blogspot.com.

FastPage: FastPage is a commercial framework that is easy to use, install, and configure.

FastPage supports ASP.NET 1.1 and ASP.NET 2.0. More information can be found at

http://fastpage.more.at.

As you can see, when it comes to choosing an Ajax framework for .NET you have plenty of choices. With the Atlas framework being an exception, all frameworks offer support for ASP.NET 1.1 as well as ASP.NET 2.0. Atlas only offers support for ASP.NET 2.0. Most of the frameworks are free.

40 C H A P T E R 2 ■ U S I N G A J A X A N D A T L A S I N W E B P A R T S

When choosing a framework we prefer not to focus on the current features of a framework, per se. We are also interested in where the framework will be two or three years from now. We expect Atlas will become the primary framework for .NET developers who are doing Ajax-style development in ASP.NET 2.0 applications. As a result, in this chapter we have chosen to focus on Atlas and ignore the other .NET Ajax implementations.

Creating Web Services in Windows