Putting ASP.NET AJAX into action

Brian Eastwood

What separates Web development with ASP.NET AJAX from "normal" development with ASP.NET?

Ajax applications have changed the way the user interacts with a Web page. An example is how user input gets processed. Before Ajax, for example, the user typically filled a form, submitted it and then had to wait for the page to re-load and notify him on the status of the operation. This resulted in intermittent interaction due to the Web page being refreshed to process the user input. On the other hand, the user was aware that the page was being reloaded because the server was processing the form.

With Ajax, we could process the same form in the background and even eliminate page refreshing, thus dramatically enhancing the user experience; but now we need to find new ways for keeping the user informed on what's going on, maybe by displaying a progress bar or an animated gif to signal that something is happening on the server. Moreover, with Ajax the user interface remains responsive while the input is being processed; therefore we have to handle new scenarios where multiple requests are sent to the server from the same page. 

In short terms, Ajax brings the need to develop new coding patterns for Web pages. With ASP.NET AJAX, developers need to get acquainted with concepts like the "partial rendering," which is a postback executed asynchronously for updating only pre-defined portions of the page layout, either periodically or based on user input. Moreover, Ajax brings the need for ASP.NET developers to become confident with JavaScript and with a new category of server controls that are aware of client-side capabilities and are able to program them. What separates ASP.NET AJAX from other Ajax toolkits/frameworks? Why will you use it over the other frameworks? What are the limitations of it over other frameworks?
ASP.NET AJAX is a set of extensions to the traditional ASP.NET programming model. As a consequence, the learning curve for ASP.NET developers is shortened significantly. On the server-side, the postback mechanism is leveraged with the introduction of the partial rendering mechanism, and ASP.NET server controls can be "upgraded" to Ajax-enabled controls. On the client side, the Microsoft Ajax Library, a JavaScript library, offers among its many features, coding patterns that are familiar to .NET developers, such as object-oriented constructs and a component model that resembles the one provided by the .NET framework. We should also consider that ASP.NET AJAX is a Microsoft product and thus developers will get full support for many years.

Regarding its limitations, I think that one could be, at the moment, the very young age of the framework. Compared to other frameworks and libraries, the 1.0 release has been out recently and needs to pass the "test" of real-life, enterprise Web applications. Moreover, the young age of the framework makes it difficult to find documentation, online literature and books on the subject.

Another issue could be the size, in bytes, of the client JavaScript framework. Being very rich in terms of features, the main script file reaches more than 50 Kbytes when compressed. On the other hand, ASP.NET AJAX offers the possibility to compress JavaScript files (not only the library files) automatically before sending them down to the browser, and the algorithm is supposed to be improved in future releases. ASP.NET AJAX comes with what seems to be a pretty robust JavaScript Library. What is included in the library and how does that benefit developers?
The intent of the Microsoft Ajax Library is to make it easier to write and maintain JavaScript code, not just sending Ajax requests. It's true that the library contains a cross-browser networking layer for dealing with the XmlHttpRequest object, but this is only a small portion of the client framework.

In fact, the library offers the possibility to debug code with dedicated methods, to perform browser detection, to use an API that offers a cross-browser interface to DOM programming. Given the various implementations of the DOM that exist around, having an API that automatically calls the right function based on the detected browser avoids writing duplicated code for each browser targeted.

Another important feature of the client library is the possibility to invoke local ASP.NET Web services and process results just by writing JavaScript code on client side. With this kind of mechanism, we can also invoke from the browser, ASP.NET Application services such as Profile, Authentication and Membership.

At a lower level, the Microsoft Ajax Library leverages the JavaScript object model with a type system that allows simulating object-oriented constructs such as classes, interfaces, enumerations. Inheritance is handled automatically and a set of methods for performing reflection on client objects is provided. In addition, the library offers a set of classes that make up a client component model similar to the one provided by the .NET framework. This means that we can create components in JavaScript and even expose properties and events. I see that you have made some contributions to the ASP.NET AJAX Control Toolkit. What is in the toolkit? What types of controls are in it?
The Ajax Control Toolkit aims at becoming the biggest collection of open-source (shared-source) Ajax-enabled controls. The Toolkit is an open source project created by Microsoft and owned by the Agility Team. Quickly, it became one of the most downloaded libraries of Ajax-enabled controls. As a result, the Agility Team decided to open it for contributions from the community.

I'm amazed by the works made by the numerous contributors who submitted powerful controls like the Calendar or the TabControl. In the Toolkit we find many controls Web developers need to add Ajax capabilities to Web sites, like the classic auto-complete textbox, Ajax-enabled validators, a dynamic modal popup and many more. I've contributed to the Toolkit with a Slider control, which uses an internal drag and drop engine embedded in the Toolkit. 


ASP.NET AJAX Learning Guide

Tip Series: Get started with ASP.NET AJAX development: Part 1  |  Part 2  |  Part 3

The Toolkit doesn't offer only Ajax-enabled controls. Instead, it provides also tools for making it easier to develop such controls. For example, the Toolkit puts in our hands a powerful framework for realizing animations and visual effects. It also offers an API for creating Ajax-enabled controls, which leverages the one provided by ASP.NET AJAX. When Microsoft released ASP.NET AJAX 1.0, it said it would be releasing the source code as well. What does that mean for developers?
The source code has been released and this opens new possibilities for developers to study and modify the code to fit their needs. Having the source code means having the possibility to debug the code in Visual Studio, for example. In turn, this can help developers to find bugs more quickly and to potentially have them fixed by the Microsoft Ajax team in less amount of time. Ajax is a great innovation, but are there any scenarios in which a developer should avoid Ajax?
Surely there are some scenarios in which using Ajax would result in a poor user experience and even in security-related issues. Let's take the two typical scenarios where Ajax is used, the dynamic update of the layout of the page and data processing happening in the background.

In the first case, we may think that manipulating the HTML on client side would always lead to better performance. Actually, this is not true in many cases, especially when large chunks of markup are processed. As a consequence, abusing Ajax in this case could even result in a huge performance drop.

Another common mistake is to perform some activity in the background without properly informing the user on what's going on, or without handling multiple requests submitted to the server. In this case, we may experience a slow-down and the page could become un-responsive or behave in unexpected ways.

There are also potential security issues associated with data transfer happening in the background, especially when invoking Web services without an authentication mechanism; or when not validating the user input properly. With Ajax, a big portion of the application code is located on the client side. As a consequence, we are exposing it to savvy users, because the JavaScript code can even be de-obfuscated without too much effort.

My suggestion is to always stick to existing Ajax patterns. At the moment, many patterns have been defined and catalogued, and many are being defined day after day, as soon as developers continue to experiment with Ajax and use it in production scenarios. Tell me a little bit about your book. What do you focus on? How is it structured? Is it geared toward beginners or more advanced developers?
Both beginners and advanced developers can benefit from our book. The book is focused on the two development models provided by ASP.NET AJAX: client-centric and server-centric. In the client-centric model, we mainly rely on JavaScript to update the page's layout and to perform data access. As a consequence, a big portion (if not all) of the application logic is moved to client side. In this case, the Microsoft Ajax Library plays the major role and four chapters of the book are dedicated to the features it provides.

In the server-centric model, we use of the glorious UpdatePanel control together with Ajax-enabled controls like Extenders and Script Controls. For this reason, the book has a chapter that introduces the server-centric model by upgrading an existing ASP.NET application to ASP.NET AJAX. Two chapters are dedicated to the UpdatePanel and one is dedicated to developing Ajax-enabled controls. There is also a chapter dedicated on how to leverage the ASP.NET AJAX Control Toolkit API and its animation framework.

An interesting chapter is the last, where we give examples of common AJAX patterns implemented using ASP.NET AJAX. We also provide re-usable code for extending the Microsoft Ajax Library itself. For a developer who is new to Ajax, what is the best way to get started with ASP.NET AJAX?
These are my suggestions:

  1. Buy our book, ASP.NET AJAX In Action.
  2. Buy a good book entirely dedicated to Ajax and Ajax patterns, without being tied to a specific Ajax framework.
  3. Study JavaScript.

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: