Monday, November 26, 2007

ASP.NET AJAX Extensions

In latest version our system we had 2 pilot projects that where developed using MS Ajax library. Overall project where a success, library can substantially decrease development
time for AJAX applications. But we also encounter number of problems and issues.

I like to list these issues for the general public use :).

ASP.NET AJAX Toolkit

Toolkit is set of additional controls what based on the AJAX extensions library, and was released by MS as open source project.
During development we noticed that controls in this toolkit where not tested as well as core components of AJAX extensions.
We encounter number of issues related to performance then toolkit controls where used inside large repeaters
and we saw functionality bugs in some of the controls.

I recommend using these controls with caution, and double check application performance and behavior during development.
Most of the times we saw what it's better to use our own solutions instead of controls from the toolkit.

Performance

Update panel is not optimal implementation of AJAX from performance perspective; it was developed on top of regular post back model of the ASP.NET
So this causes for information that is usually transferred during post backs to be transferred during async requests as well.
This includes values of all form inputs as well as view state. This additional data causes request to be very bloated even for most simple things

In addition on the server side full page life cycle will be performed.

So from performance point of view:

It's better to make more things on client by using JavaScript instead of making async post back to the server.
Better to use Ajax web services instead of Update Panels, this will post only data that you explicitly wanted to send.
If you using Update Panels try to minimize amount of view state on the page.


Session/ Authentication Time Outs

Another issue with AJAX development, you need to be aware is timeouts in session and authentication.
If user make a regular post back in ASP.NET application and his authentication is timed out he will be redirected to the login page.
It's great but if it's happens inside of asynchronous requests this behavior will cause error on the main page instead of appearance of a login page.
Additional code is needed on client/server to handle such scenarios.

Please be aware of this issue during development and testing.

Usability consideration

When user performs action using regular post backs, he always gets a feedback in the form of flashing status bar
and other visual effects build in the browser, on the other hand Ajax request by default are invisible so it's not clear if something is working
correctly or not when action is performed.

So if request is long we need to give user visual feedback for example in form of "waiting" popup.
AJAX extension provide special Update Progress control to make development of such pop ups simple.


Debugging

If you encounter mysterious problem, instead of making a lot of guesses start investigation is by running Fiddler and look into requests and responses.
It will remove a lot of mystery from the problem :). Another very good tool is Firebug extension for Firebox.
It has a lot of useful tools including performance profiler for JS, very informative debugger, DOM browser and others.

Error handling

AJAX extensions provide facilities to handle errors that came from async requests; you can use them to show friendly messages to the user instead of red exception screens

2 comments:

Tim said...

Interesting, thanks for the info.
While I have no experience (yet) with MS's AJAX implementation, I've found the standard ASP .Net controls do not deliver all the ease of use that they promise, so it rings true that ATLAS, or whatever it's called now, would be the same.

Mikhail_T said...

Don't get me wrong , MS Ajax Library has advantages, in developer productivity.

It's very easy too make you existing ASP.NET application more AJAX complaint by just taking few UpdatePanels and slapping them around you existing pages.

But if you don't careful and not aware of underlying problems the end result will be not that good.