Hi,
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
Hi,
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
If you are comfortable with the whole ASP.Net postback scheme, one advantage of sticking to such controls is that (most of the time) they shield you from side effecs from postbacks and such. But in this specific case it comes with a cost: you have a full postback for each AJAX request (which will include view state), which can be a performance hit compared to a straight AJAX request, cf:
http://geekswithblogs.net/dlussier/archive/2007/09/06/115188.aspx
I am also not sure on whether it handles well cross-site requests (JSONP and such), so these are two caveats to consider.
Sure, IMHO you should prefer jQuery over the standard ASP.Net update panels. the reason (main) is performance, when you post some data using jQuery.ajax you only post what the server needs to understand the post. this is usually 1-2 parameters of text.
when you do the same post using an update panel, the entire page goes for a walk behind the scenes to the server, then the entire page returns and the area is rendered.
if you use jQuery, you can create an ashx page on the server, this one doesn't have the Page load and lifecycle of a regular webform and it is also very lightweight.
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...)
I would say that you should definitely favor jQuery AJAX over the ASP.NET AJAX UpdatePanel. If you look at the ASP.NET AJAX site, there really isn't a mention of ASP.NET AJAX and/or the UpdatePanel...but there is a lot of mention of jQuery. In fact, it looks like Microsoft is favoring ASP.NET developers using jQuery as the client-side JavaScript AJAX framework over UpdatePanel and the related ASP.NET AJAX controls.
They still provide links to the AJAX Control Toolkit, but with so many jQuery plug-ins out there, why would you need the Toolkit?
UpdatePanel is slower and bulkier -- go with jQuery AJAX.
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:
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.