views:

127

answers:

2

I keep hearing that the server side ASP .NET AJAX controls (like UpdatePanels) are not truly AJAX though they seem like it, because rendering is not completely on the client side. I'm trying to understand this with more clarity. Could someone elaborate?

Thanks...

+1  A: 

http://msdn.microsoft.com/en-us/magazine/cc163480.aspx

Maybe this will answer???

I hope. (Reading it as well).

Seems to me that the Control is a Server Side object that uses ajax as a mechanism and that the ajax is rendered to do the client side. In this sense It isn't pure ajax but, rather a blending of multiple solutions.

:)

Joe Garrett
+12  A: 

UpdatePanels came out fairly early in the AJAX cycle, and they're heavy (they can emit around 100-300k of JavaScript). Behind the scenes, UpdatePanels post the entire page back to the server via a JavaScript XMLHttpRequest. The new page is generated with the normal page lifecycle just like a postback, but only the parts that live inside the UpdatePanel (plus the parts necessary for updating ViewState and so on) are sent back to the client. From there, the markup is inserted without a visible flash or interruption of page state.

Most competing AJAX tools lean towards super lightweight implementations that let you ship or generate a small chunk of HTML via Javascript, and I would say that's the dominant direction today, especially outside the ASP.NET world.

The difference in total amount of data sent across the wire is huge -- see the link below. In low-traffic situations it might not make a bit of difference, but in the case of a site like StackOverflow, it would show up on the bandwidth bill for sure.

All that said, I don't think it's fair to say that UpdatePanels are not actually AJAX, since they do ship HTML around via asynch JavaScript -- it's just that there's a gigantic, often cumbersome framework on top. UpdatePanels get a bad rap sometimes, but they provide a brilliantly simple developer experience. I've often found them useful in low-traffic situations.

Update: Here is an article (old but still valid) that examines the payload UpdatePanels ship to and from the server. It also goes into Page Methods, which is a lightweight, Web Service-based alternative to UpdatePanels. This is an oft-overlooked part of Microsoft AJAX.

Brian MacKay
tl;dr; they are by definition, but most of what they do is eliminate a postback and some rendering. Good description.
GoodEnough
@GoodEnough - Thanks. :) I agree with you, although I think eliminating a heavy server roundtrip and rendering is the main point of most AJAX tools. And I will also say that the rendering thing is a big deal in some cases. I had one situation where I was doing front-end optimization on a huge line-of-business .aspx, and as it turned out, the perf bottleneck was not the database or even the network -- it was rendering!
Brian MacKay
@Brian - Yes, rendering can be a very big issue (we're having problems with IE users because of that in one of our applications). UpdatePanels work until you start working with bigger pages with lots of data and a big ViewState (damn ViewState).
GoodEnough
@GoodEnough - Yes, damn viewstate. In the situation I mentioned, viewstate was actually a big part of the problem. But then I learned that I could persist it to session with just one line of code. In my scenario we had (a) a very small user base and (b) session state server already active. So it was perfect.
Brian MacKay
So the result is rendered in the server and shipped back to the client, but only the content within the updatepanels is updated? Other AJAX frameworks like JQuery work the same way, right? Only difference being, that the update panels send the entire page contents back and forth--which means, visually it looks likes AJAX by not having the page refresh, but performance-wise, it's equal to a non-AJAX page?
Prabhu
@Prabhu Check this out: http://encosia.com/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/ it examines the HTTP post/response of an UpdatePanel. In short, a lot of data gets sent across the wire (viewstate, form fields, etc) and a lot of data gets sent back. When you get right down to the performance, the fact that the page does not refresh often means that from the user's point of view, it performs much better than a normal postback! Rendering is sometimes my main perf bottleneck these days. The whole page lifecycle that occurs leads to some waste, but is also quite powerful.
Brian MacKay
@Prabhu So I would say, you just have to know the pros and cons of the various approaches. UpdatePanels waste some bandwidth, but for many sites the cost buys you a lot of developer productivity and maintainability. It depends on whether you're building a site for 20 users or StackOverflow, which has millions.
Brian MacKay