Before I start talking about AJAX I just want to point out, as many have, that the
technologies and approach that comprise AJAX have been around for ages. I was
using asynchronous client side XML calls over 4 years ago. But in any case
there's nothing like a catch phrase and a formalisation of ideas to generate hype.
So moving on...
I found a great AJAX wrapper for .Net at http://ajax.schwarz-interactive.de/csharpsample/default.aspx.
What I really like about this implementation is that it implemented in a way that
is similar to web services. To define a server side AJAX method (i.e. one that
will be called asynchronously from the browser client), you simply add the AjaxMethod
attribute, like this:
//C#
[Ajax.AjaxMethod()]
public bool ValidateZip(string Zip)
{
return (Zip.Length
> 0);
}
The framework supports a large range of types such as bools, ints and any serializable
class, so one has quite a bit of freedom in terms of what can be returned and passed
in to the methods.
One however has to register the class for AJAX participation (note that this
does not have to be a codebehind class, i.e. one that inherits from Page), like
this:
Ajax.Utility.RegisterTypeForAjax(typeof(AddCustomer));
The framework then automatically emits a JavaScript object for the registered class
using a dynamically generated ashx file to allow one to hook up the client code
to the server. So in this instance one, it would have generated an AddCustomer
JavaScript object with a ValidateZip function. To use it from the
client one would call AddCustomer.ValidateZip(value); which
would trigger the XMLHttp call back to the server (which is handled by an ashx page).
Obviously with this approach the framework's ashx page handler needs to
be registered in order for it to function properly. This is done like so:
<httpHandlers>
<add verb="POST,GET" path="appvirtualdir/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
</httpHandlers>
I think Michael Schwarz has done a great job with this framework and it is definitely
something I would consider using in the future.
Microsoft are also coming out with an AJAX framework for .Net 2.0 called Atlas.
It will be interesting to see how the implementation will differ from Ajax.Net when
it is released.