AJAX for .NET – Don’t use Prototype…
I have been using the Prototype AJAX library for a little while now to add AJAX capabilities to my PHP web applications. It works great! It works so great in fact that I tried to use it in an ASP.NET2005 project recently. After figuring out that my CSS and Theme support could thank the Prototype library for its troubles (they didn’t work at all) I went looking for a new AJAX library for .NET.
Was Prototype a bad library? No, it was and is a great library. The automated nature of the .NET framwork and the way it mangles the names of controls and auto generates script events creates a conflict between the Prototype library and .NET. If you are planning on using PHP or other web languages, Prototype is a great choice.
I read some reviews and dug around a little bit and I came up with MagicAjax as the favorite for a .NET Ajax implentation. Let me tell you, once you get it included/referenced into your project properly, it is an absolute joy to use! It is SOOO easy! It automatically adds AJAX features to existing controls! It gives you Postback withouth the Postback. All you really have to do is add an Ajax Panel control and place any controls you want Ajax Enabled into that panel and presto! It’s done! The click or change event will now happen via the Ajax wrapper.
The secret is that the MagicAjax Panel control will modify its child controls when they are rendered so that they fire the Ajax event rather than the Post Back event. Like I said, this happens automatically for any controls placed inside the Ajax Panel. You can override this functionality and turn Ajax support off for particular controls. You can also use multiple panels to create groups of controls. This is a great feature as it allows you to send only the needed information to the server.
Here is an example. Ever notice on car sites that you can search by make and model? Well, model should change depending on which make is selected. There are many ways to do this dynamically (I wrote complex javascript arrays in the past). With Ajax, you can populate that list from the server in real time from a database list. The Ajax Panel could wrap just these two controls and leave the rest of the page alone. This can greatly reduce the ammount of information that has to be sent and returned from the server.
Check out MagicAjax at http://www.magicajax.net/. It is a great libaray and makes adding Ajax capabilties almost transparent. Note that it is easier to setup in ASP.NET 2.0 than in version 1.1, but once it is setup, it is just as easy to use.
Ray Pulsipher
Owner
Computer Magic And Software Design