Jess Chadwick

Your Friendly Neighborhood Webinary
The ASP.NET AJAX Client Library: Keeping the Server-Side Paradigm Alive on the Client

I've been talking a lot lately about using the ASP.NET AJAX client library (which I'm going to refer to as AACL in this post) without the server-side controls, mostly in the context of ASP.NET MVC.  Now, I'm not necessarily recommending that you use it over any of the other fine JavaScript libraries out there (jQuery and MooTools come to mind), but for ASP.NET developers, it offers an interesting twist to client-side development.  The ASP.NET team put a good deal of effort into helping keep the same paradigm across the server-client divide meaning that you end up having the same types of concepts at your disposal on the client-side as you're used to with server-side Web Forms development.  For instance, here's an example of how you make a (manual) AJAX request on the client side:

An ASP.NET AJAX client-side AJAX call
   var request = new Sys.Net.WebRequest();
   request.set_url('http://myapp/customers/1234');
   request.set_httpVerb("GET");
   request.add_completed(some_function);
   request.invoke();

There are a few interesting things that I find interesting about this code snippet due to their similarity with general .NET and/or Web Forms development:

  • Fully-Qualified Namespaces:  I'm referencing the piece in the first line - "Sys.Net.WebRequest".  The AACL supports the concept of namespaces, just as you're used to when dealing with the .NET Framework.  The benefits of being able to use namespaces should be obvious.  Unfortunately, there is a downside to this as well - a class that may have been called simply "WebRequest" is now just about twice as long... and considering the fact that every byte down to the client matters (and you're almost certainly going to be referring many of these classes), this may end up representing a good deal of bloat in your application
  • Property behavior:  the example above happens to only use setters (e.g. request.set_url([...])), but the AACL makes heavy use of the "Property" metaphor, preferring the use of foo.set_XX() and foo.get_XX() to access your fields and promote encapsulation.
  • Event Handlers:  on line 4, you can see an example of adding a handler to the "completed" event of the request object.  Of course, events and delegates are nothing new to JavaScript, but the AACL offers some nice functionality to help manage the adding and removing (registering/de-registering) of these delegates.

It is concepts such as those I mention above (and plenty more) that make the ASP.NET Ajax client library quite comfortable to use when doing client-side development - with or without Web Forms.

Posted: 11 Jul 2008, 15:48
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS