Brendan Tompkins
Implementing AJAX requires more than a few technologies on top of ASP.NET to get going. So when you’re faced with implementing AJAX in your web apps you have to make some decisions about how much help you’re going to get with all this stuff. I thought I’d post a bit of information I’ve gleaned about the different options that you have currently for developing AJAX enabled web apps on ASP.NET...."> Getting Started with AJAX on ASP.NET - Brendan Tompkins [MVP] - CodeBetter.Com - Stuff you need to Code Better!
 
Brendan Tompkins [MVP]

Sponsors

The Lounge

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Getting Started with AJAX on ASP.NET

I’m nearly done with a new version of WSMQ that runs on ASP.NET 2.0 and contains a nice snazzy new AJAX interface. Since along the way I learned a little about this new fangled technology, I thought I’d post a bit of information I’ve gleaned about the different options that you have currently for developing AJAX enabled web apps on ASP.NET.  

This Post is like, so September 2005.
Yes, I know, you’re probably already really familiar with AJAX by now, and may have even decided how you can most easily add AJAX to your apps.   If this is so, you may want to skip this post and head directly over and stream the new Belle & Sebastian album or  decide for yourself if this is really proof of aliens landing in Iowa in 1913 or an elaborate hoax (remind me to tell him that I think I saw Benjamin Stove at a .NET user group meeting…) .  Or just sit there in amazement and ponder how this guy made $1M selling ads on one page.

Oh, you’re still here.. Okay, well, so you you may be wondering how to get started implementing AJAX within your own applications.

What is it AJAX Again and what does it have to do with ASP.NET?
You know, that Live.Com Google Maps stuff. Basically AJAX is dynamic web content without the postbacks. To implement it, however, it requires more than a few technologies on top of ASP.NET to get going.   Specifically, it requires manipulating the Document Object Model through JavaScript to dynamically display and interact with the information presented, and the use of the the XMLHttpRequest object to exchange data asynchronously with the web server.   So when you’re faced with implementing AJAX in your web apps you have to make some decisions about how much help you’re going to get with all this stuff.

There are the brave few that will decide to go it alone, and code directly to the browser’s object model. If you are interested in rolling your own scripting the browser’s XML HTTP functionality, there’s a good article here on how to do just that.  Sahil, a while back, posted an example on how to create a progress bar using AJAX.  The problem with this approach is that it requires knowledge of a multitude of technologies, and I’ve found this can be quite tricky to code, debug and maintain.  If you’re like me, you want to spend less and less time writing client end code and concentrating on something more re-usable.

Just the AJAX Script Libraries, Please
There’s more than a few Javascript libraries around which do the dirty work of DOM manipulation and XMLHttpRequest processing for you.  One option for deploying an AJAX app is to implement your solution based on one of these libraries. You’re still going to need to know quite a bit about JavaScript to use these libraries, but they are out there if you need them.

Prototype

“Prototype is a JavaScript framework that aims to ease development of dynamic web applications. Featuring a unique, easy-to-use toolkit for class-driven development and the nicest Ajax library around, Prototype is quickly becoming the codebase of choice for web application developers everywhere.”

Sarissa 

“Sarissa is a cross-browser ECMAScript library for client side XML manipulation, including loading XML from URLs or strings, performing XSLT transformations, XPath queries and more. Supported: Gecko (Mozilla, Firefox etc), IE, KHTML (Konqueror, Safari).”

ASP.NET Ajax Implementations
So if what you really want to be doing is concentrating on business logic, application design and creating loosely coupled services/objects that your organization can reuse and build upon,  you don’t want to be wasting a ton of time coding up in the UI. Especially since you’re probably going to have to rewrite the UI again anyway when the next new presentation technology comes out.   The fastest way to implement AJAX, given this, is to use an implementation that quickly plugs into the ASP.NET framework and allows you to write the least amount of custom AJAX code. There are a couple of alternatives for doing just this.

Ajax.NET Professional

This is a free, open source AJAX library is written by Michael Schwartz.  From what I can tell, it seems to be very poplar, although the project seems to have branched a bit and it’s kind of hard to tell where it’s headed.  There’s a good MSDN article here that will help you get up and running using Ajax.NET.

JAAJAX

Jay Kimble’s implementation based on the Sarissa AJAX library. Uses method attributes to declare AJAX-accessible server code.  Jay can tell you more, in fact he’s right next door..

ASP.NET “Atlas”

ASP.NET “Atlas” is a package of new Web development technologies that integrates an extensive set of client script libraries with the rich, server-based development platform of ASP.NET 2.0. “Atlas” enables you to develop Web applications that can update data on a Web page by making direct calls to a Web server — without needing to round trip the page. With “Atlas”, you can take advantage of the best of ASP.NET and server-side code while doing much of the work in the browser, enabling richer user experiences.

Microsoft’s AJAX offering is pretty nice.. It was demo-ed in the PDC 05 keynote which I missed unfortunately… Comes with a Visual Studio web site template, and quite a large feature set. I managed to get a simple AJAX web form implemented in a matter of minutes.  Scott Guthrie has a great walk through here for creating a quick Atlas app.

ComponentArt’s Callback

This is the AJAX implementation that I’m most familiar with. It’s pretty sweet. “Adds cutting-edge AJAX (Asynchronous JavaScript and XML) functionality to the other components in the Web.UI suite and also "AJAX-enables" virtually any ASP.NET control!”

Telerik’s Callback Suite

“r.a.d.callback is a suite of AJAX-enabled UI controls, which allow you to update page content without postback and loss of scroll position. The short response time combined with the smooth interface transitions results in superior users experience and level of interactivity, which can only be found in desktop applications.”

Is that it?
Heck no! I’m sure I’ve failed to mention more than a few technologies that are out there. If you know of any, please post them via a comment here. 

Good luck!

Brendan


Posted 01-26-2006 4:12 PM by Brendan Tompkins

[Advertisement]

Comments

Eric Wise wrote re: Getting Started with AJAX on ASP.NET
on 01-27-2006 7:47 AM
I actually prefer telerik's callback suite to the others. The component art was OK but the Telerik one felt more intuitive to me.

Feature wise I also think the Telerik one has a few more features. I recall having a problem with the component art not updating the viewstate... so I could display new values but on a real postback they were gone.

Have you experienced this or was it just something I was doing wrong?
Brendan Tompkins wrote re: Getting Started with AJAX on ASP.NET
on 01-27-2006 9:11 AM
Eric,

I haven't used the Telerik one, but haven't had any major problems with ComponentArt's either..

I'm not sure I've tried to do what you're doing, though. It does seem that when using these controls, you have to work around things here and there.. I've found that AJAX works best for master-detail display stuff mostly, not with edit forms..

The Atlas code looks promising for separating parts of the page that require postback and having other regions work via AJAX. Have you experimented with it?

B
Sam wrote re: Getting Started with AJAX on ASP.NET
on 01-27-2006 7:02 PM
I think the idea of an Ajax control has limited utility, but that's my opinion on controls in general so YMMV.

Something you might want to dig into is the declarative nature of HTML "programming" with libraries like Behaviour. Such as...

On a recent project we used a custom sorttable.js and Behaviour to add javascript sorting to every table in the website without changing a single line in the tables themselves (not even so much as an attribute). We just followed a few simple conventions, such as data tables should have THEAD>TR>TH for headers, TBODY>TR>TD for data, and TFOOT>TR>TD for non-sortable footers.

We added translation magic by generating spans server-side that had "english" and "japanese" attributes. The language switching javascript function used documents.getElementsBySelector('span[{0}]'.format(this.language)); to find all translateable elements and swap the innerHTML. No messing with state of postbacks or anything, just a simple js function. A better way would've been to make an Ajax request for some JSON and replace matching phrases, but we were pressed for time so didn't think of it until later.

A really nice usage for Ajax is form posts. This way we avoid the whole double-submit thing, POST page warnings when navigating history, and it makes the application seem more responsive too. So POSTS are an ideal place to go crazy with Ajax since you have all the benefits, and none of the drawbacks as you do with using Ajax for normal GET requests.

But Javascript is a really nice/powerful little language once you dig in.
Brendan Tompkins wrote re: Getting Started with AJAX on ASP.NET
on 01-29-2006 4:26 PM
Sam,

I used to be a big believer of hand coding browser tier stuff, but as my apps grew, I realized that each piece of hand-coded code I wrote required maintenance by me, was more buggy than packaged controls, and in some respects was what some call "alien artifacts"... things that get left behind by consultants that are not easily understood by future teams inheriting my work.

For these and a lot of other reasons, I'm leaning more toward the buy don't build philosophy... and I can't think of a better justification for this than with an AJAX control. There's so many mixing technologies, it just makes sense to me to use a control...

I really like using controls that I can bind and follow typical asp.net patterns in development, and focusing my time on backend design..

-Brendan
Sam wrote re: Getting Started with AJAX on ASP.NET
on 01-29-2006 8:29 PM
As usual I've written a reply that was much too long. ;-) So instead of polluting your blog, I've posted it to mine (if you're curious).
kierepka wrote re: Getting Started with AJAX on ASP.NET
on 01-30-2006 7:10 AM
You forgot about MagicAjax.NET
(www.magicajax.net)

Kind regards from Poland

Brendan Tompkins wrote re: Getting Started with AJAX on ASP.NET
on 01-30-2006 9:18 AM
Just wanted to post a link to Behaviour as a followup to Sam's comments. This does seem like a much better way to work with client side JavaScript code.. Check it out here.

"Behaviour is the missing link for your ajax apps."

http://bennolan.com/behaviour/
Scott wrote re: Getting Started with AJAX on ASP.NET
on 01-30-2006 2:24 PM
Prototype is a great library. I've looked at several asp.net based AJAX libraries including ATLAS. So far, none of them have given me goosebumps or made me really smile. ATALS is really starting to show promise. I still end up writing methods or controls in ASP.NET to get the data down to the client rather than using a server-side library to magically output my AJAX code. Personal choice I guess.

My favorite AJAX library is based on the Prototype lib. Rico. http://openrico.org/rico/home.page

I like the effects in Scriptaculous, but I haven't had a chance to use them in any of my code yet.
http://script.aculo.us/
Mateusz Kierepka wrote re: Getting Started with AJAX on ASP.NET
on 01-31-2006 10:48 AM
And Castle project :)
http://www.castleproject.org/
Stuart Radcliffe wrote Recent Links
on 02-06-2006 2:09 PM
the blog of michael eaton wrote Link Dump for Wednesday, February 8, 2006
on 02-08-2006 11:23 AM
balu wrote re: Getting Started with AJAX on ASP.NET
on 11-27-2006 6:36 AM

ok

Max wrote re: Getting Started with AJAX on ASP.NET
on 02-19-2007 3:55 PM

Atlas is too large and too slow to use in a large ajax application.  All of that classical OO javascript framework they have created is neat but you pay for it in performance.  IMO, you shouldn't be doing ajax apps unless you know and understand javascript and the DOM.  JS is a simple language, I don't see why everyone wants to abstract it.  Take the time to learn it and your clients will thank you in the end.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?