Ajax: What the hell is the buzz all about?

time to read 4 min | 676 words

So today I had used ajax functionality for the first time. By that I mean that I used Ajax as it should be use, to show a progress bar for a lengthy process (about 1 minute).

What I wanted is to load a page with a progress indicator, and at the same time, start the action in the server, when the results are ready (a grid), they would be sent to the client, which would replace the progress indicator with the gird. The current result set is about 5,000 items (expected to be aroudn 50 - 100 in production, though), so it should be pageable once it is calculated.

The upstream team is using atlas, so I decided to take a look at this. It took me about five - ten minutes to determain that to implement the functionality in atlas would take quite a bit of time, since I know nothing about atlas except that update panel doesn't play nice with validation on my pages.

I briefly considered using prototype to handle the functionality, but that would mean bringing an additional server side functionality that I would have to deal with, which I am not thrilled about, or handle the call myself, which is not something that I have a particular wish to do. Therefor, I looked into ASP.Net 2.0 callbacks.

After reading a couple of articles, I began searching for the right progress indicator (I really like this one, but this one was the final choise), which took about 25 minutes. I then implemented ICallbackEventHandler and wrote the javascript functions that would replace the waiting indicator with the grid when it was done in another 30 minutes.

The most major issue that I had to deal with was that calculating the result is expensive, so it should be cached, but it is only valid for a single page visit. I decided to put the cache key in the view state, which would enable me to keep the calculation as long as the user remained on the page. (Basically, browsing through the data, not much more). But because the calculation is happening as the page is loading, it was neccecary to maintain the cache key when called from the callback (which doesn't trasnfer view state, as far as I can tell).

There were some issues with the Page Lifecycle, of course, and you can't just render a grid to string, you need to disable event validation at the page level (only using markup, not in code) or you will get null reference error. But I consider this life in the ASP.Net WebForms world.

Overall, including learning how to do this, it took about two hours, going from a white screen for a minute or so to fully featured ajaxified page. No external code except what is in ASP.Net 2.0 (I really wish that I could have used MonoRail, it has prototype and supporting framework already builtin, and no page lifecycle).

Ajax? Can you tell me why I, as a developer, should find it interesting? Sure, Gmail and the like are really nice. But interesting technology wise?  I see a lot of cases where people are shoving Ajax into every little bit of the application (you are replacing the bottom half or the page, and the lower half of the page... and you do it with ajax... to avoid page refresh, I see...).

Building applications should be about usability, and you don't get that by throwing indicators all over the place or making each and every text box auto complete.

And to the buzzword-wize fellow out there, putting web 2.0 on your resume... put you on the direct path to marketing...