Considerations for AJAX UpdatePanel, Page Methods and Web Services

I would not even pretend to be all knowing here but I couldn't stop myself from sharing this chain of interesting links which should remind all of us of the dangers of abusing UpdatePanels thinking that using it in any way will make our old non asynchronous pages work like magic. [more]

My journey starting with this post : Why do ASP.NET AJAX page methods have to be static? which happened to be included in ScottGu's April 28th links.

I have known and heard page methods before but haven't really used it as much as I use UpdatePanel but you ought to read that link and from there you should view the link on Why ASP.NET AJAX UpdatePanels are dangerous (the text being linked in the article is actually "They are especially performant compared to the UpdatePanel’s partial postbacks.") but I find the real title more interesting. It might not be true as "danger" is indeed relatively. But to give you a short note, UpdatePanel is still posting back to the server (including ViewState et al), it just does that asynchronously but bottom line is that a lot of information is still being sent back and forth from server-client and in some cases that is a lot of unnecessary information. I would suggest going through the article including the comments as there really are cases where Page Methods or UpdatePanel is more appropriate but bottom line is we ought to know them and just because we use UpdatePanels it doesn't mean we have the best AJAX solution.

This reminded of a case where I had a calendar control inside an UpdatePanel and looks fast locally but when deployed to a test server was considerably slower. Turns out that the page itself has a large viewstate and async postback triggered by the UpdatePanel brings that large viewstate to the server. In addition, the page will also be reconstructed (control values/properties) thus an additional overhead.

The asynchronous processing is likely to help but think again as a pure Javascript solution might be better, or PageMethods (which is sort of a easier/or at least a close alternative to having ASMX (web services)).

Check out this link on Exposing Web Services to Client Script which includes a discussion, source and sample for Page Methods.

And also if you want to hook client side events of UpdatePanels (eg. Begin/End Requests) check out this link : Use the PageRequestManager to Get More Control of Your UpdatePanels

This stuff is also a good review for upcoming ASP.NET 3.5 MCTS as there were a lot of items involving Client Scripts (more than knowing what UpdatePanel's are and which property to set for which).


Posted

in

by

Tags: