Design

Gaia Ajax: A New Approach to ASP.NET AJAX

By Dino Esposito, December 08, 2009

A set of ASP.NET server controls with the same programming interface as AJAX

One sign of Microsoft ASP.NET's popularity is the wide availability of custom server controls that extend the web application framework by targeting the AJAX paradigm. AJAX controls provide a client-side object model that developers can use JavaScript to code against. In this way, developers can, for instance, attach a data source to a grid control and populate cascading drop-down lists when one of the selections changes. To work with today's typical AJAX server controls, developers also need a layer of ad hoc services that return JavaScript Object Notation (JSON) data to be manipulated on the client side. Microsoft and third-party vendors like Telerik, ComponentArt, Devxpress, and Infragistics are actively providing tools and solutions for this model.

The usual approach to AJAX-base development forces developers away from the familiar programming model of classic ASP.NET Web Forms. Instead, developers tend to use JavaScript instead of C#, and bind to JSON data instead of .NET data types. Is there any alternative?

In the early days of AJAX, a few members of Microsoft's ASP.NET team proposed to expose from the ASP.NET platform a set of server controls emitting both rich script and markup. Unfortunately, this approach never gained enough traction to become an actual implementation. Consequently, today's developers have to learn a new programming model and take the plunge into JavaScript to do AJAX effectively.

An alternative is Gaia Ajax, a little known commercially available library that does what Microsoft was about to do years ago -- that is, offer a set of ASP.NET server controls that have the same programming interface as AJAX. Gaia Ajax offers relatively low-level controls such as Button and TextBox that are, for the most part, derived from original ASP.NET controls but enriched with the unique capability of supporting asynchronous AJAX postbacks instead of plain postbacks.

For example, when you write a Button1_Click event handler, you know that your code will be executed in response to a client request. However, any response will be sent to the client and displayed without refreshing the entire page. The Gaia Ajax library also features a GridView control that, in turn, inherits from the base GridView control of Web Forms. Using the Gaia's GridView is no harder than using the classic GridView -- the programming interface is nearly the same. However, paging, sorting, in-place editing, row selection, and checkability of rows are all fully AJAX-compliant, and you don't have to write a single line of JavaScript code.

Moreover, Gaia Ajax encourages developeers to continue using the familiar programming style of ASP.NET Web Forms. AJAX comes free with the surrounding library. Had Microsoft done ASP.NET AJAX this way, we could have upgraded our applications to the next version of ASP.NET gaining AJAX capabilities almost for free.

So what's the difference between Gaia Ajax and ASP.NET-style partial rendering? Both preserve the classic ASP.NET programming model. With Gaia Ajax you don't need to use the ScriptManager control, nor wrap your controls in a special updateable panel. Neither does partial rendering allow multiple simultaneous calls. If two calls occur at the same time, then the oldest is killed to make room for the newest. Gaia Ajax, instead, employs a queue transparently. Finally, with Gaia the update of the page is faster because it is smarter. While partial rendering refreshes a portion of the page by setting the innerHTML property to a new HTML string, Gaia Ajax controls keeps in sync the server-side tree of controls with the DOM-level tree of controls. Any updates, in the end, are applied by modifying the individual element in the client DOM tree without erasing and replacing the entire tree.

What makes Gaia Ajax worth considering is just its underlying architecture -- it lets you avoid additional learning curves by allowing you to do your AJAX-based development in an ASP.NET familiar way. In other words, you keep on writing ASP.NET apps, except with Gaia Ajax they're automatically AJAX enabled.

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task.
However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Video

This month's Dr. Dobb's Journal

This month,
Dr. Dobb's Journal is devoted to mobile programming. We introduce you to Apple's new Swift programming language, discuss the perils of being the third-most-popular mobile platform, revisit SQLite on Android
, and much more!