Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a reason to prefer jQuery.Ajax to asp.net UpdatePanel?

If I am developing an asp.Net application, can there be some cases where I should forget about MS Ajax UpdatePanels and prefer jQuery.Ajax to update some part of my page?

Thank you

like image 293
pencilCake Avatar asked Jul 20 '10 12:07

pencilCake


2 Answers

As others have stated, MS-Ajax and UpdatePanels perform poorly - sometimes to the point of being unusable. As others have pointed out, the ajax callbacks which should be small & lightweight, are heavy because they also include the full ViewState.

In addition to those issues, I found some other drawbacks to MS-Ajax:

  1. The MS-generated javascript includes a LOT of overhead. They've built in a lot of type-checking and variable-checking, with the intention of making their javascript more typesafe, I assume. This overhead slows down the browser-side processing significantly - especially when those generated javascript functions are being called repeatedly/recursively (as is the case with some 3rd-party controls).
  2. The ASPX code-behind becomes much more complex and harder to maintain, because the same page lifecycle is being executed for the initial loading of the page, as well as every single ajax callback. Like all complex code, this can be overcome by skilled developers and good code comments - but it's nevertheless a drawback to consider.

A final note: the one benefit to MS-Ajax & UpdatePanels is, you can get away with being 90% javascript-ignorant and still code them. "Traditional" ajax involves FAR more javascript coding than MS-Ajax.

like image 87
mikemanne Avatar answered Oct 19 '22 14:10

mikemanne


Yes, in fact, you should almost always prefer using your own (or jQuery's) ajax functionality before.

There is a lot of overhead associated with the MS Ajax UpdatePanel (it performs a full postback, and then updates the element(s) that changed on the page), so the nice features in an AJAX enabled web site - responsivenes, continuity etc - are almost entirely lost (IMHO). You have very little control of what is actually submitted over the cable, of what is returned, and of how it is treated upon return to the client.

With jQuery Ajax on the other hand, you get full and instant control, you can make as light-weight (or heavy) requests as you wish, and lets face it - the API isn't in any way harder to use than that of the UpdatePanel.

With that in mind, there are still scenarios when the UpdatePanel is fine, or even better. Especially in ASP.NET WebForms, it can be tricky to return just part of a page in a way that gracefully degrades if the user can't use javascript, and for the rapid "drag-and-drop" development style, there is really no way jQuery can compete. (Whether you like drag-and-drop development or not is an entirely other discussion...)

like image 43
Tomas Aschan Avatar answered Oct 19 '22 14:10

Tomas Aschan