3

TLDR: UpdatePanels or PageMethods?


As far as I can see, there three ways to build ASP.NET Web Forms applications:

  1. Full-page, synchronous postbacks
  2. Partial, asynchronous postbacks using UpdatePanels
  3. PageMethods (and web service methods) and manual JavaScript
  4. (I know there's ASP.NET MVC as well, but that's not part of the Web Forms family.)

I think everyone agrees nowadays that Option 1 no longer provides a satisfying user experience. (It might have worked for a while, but SmartNavigation got deprecated a long time ago, only supported IE and was never as stable as it should have been.)

The problem is that Option 2 and 3 don't really work together: As soon as you try to do something non-trivial with PageMethods (like filling a list with entries), the view state breaks, thereby breaking existing "UpdatePanel-based" code. Currently, there's no easy way to work around that.

Since UpdatePanels and PageMethods seem to be quite incompatible with each other, is there some official recommendation on which one to use for new projects?

To prevent this from becoming a subjective question, I'd like to restrict this question to official statements from Microsoft and (semi-)official statements from Microsoft employees.

Community
  • 1
  • 1
Heinzi
  • 167,459
  • 57
  • 363
  • 519

1 Answers1

0

As I'm sure you can imagine, the answer to this question is very much "it depends." As you've sidestepped the subjectivity of a question like this by asking for official Microsoft endorsements, though, how about this video by an ex-MS employee, from an official Microsoft source. The summary of the video does a fairly good job of summarising (which is good, given that it's a summary):

The first method is to use an UpdatePanel, where no additional code needs to be written on either the client side or the server side. The benefit of using the UpdatePanel is that everything works automatically. The penalty is that at the client it requires a lot of data to be included in the AJAX request and response, and at the server it requires a full page lifecycle to be executed. The second method is to use network callbacks, where additional code needs to be written on both the client side and the server side. The benefit of using network callbacks is that at the client it requires very little data to be included in the AJAX request and response, and at the server it requires only the called service method to be executed. The penality is the time and effort it takes to write the necessary code.

Subjective, unofficial bit:

Personally, I would avoid using UpdatePanels almost all of the time; as with a lot of WebForms features, they take control away from you and introduce a lot of nasty markup and excess (and usually inline) JavaScript, which can cause you all kinds of unexpected behaviour when you have a modern, feature-rich web application. PageMethods let you control this yourself, in line with your own development practices.

If they won't work together then, as I see it, it comes down to the question, "can I be sure that UpdatePanels will give me everything I need?" If not, your decision is made.

To my knowledge, though, neither approach is officially deprecated or "advised against."

Ant P
  • 24,820
  • 5
  • 68
  • 105