15

What are the advantages and disadvantages of using Ajax update panels in ASP.NET application. Is there any alternatives available to avoid the use of Ajax update panel?

Mat
  • 202,337
  • 40
  • 393
  • 406
Sauron
  • 16,668
  • 41
  • 122
  • 174

5 Answers5

22

Advantages:

  1. Easy to use and configure (Well, I don't know of any other advantages!)

Disadvantages:

See here and here
Now for the best part, the alternatives:

Use jQuery's built in support for Ajax to make GET/POST Ajax calls, it's very simple (simpler than the update panel I would say), and absolutely compatible with most browsers!
An example of using one of the many easy ways jQuery provides for doing Ajax calls:

  $('#anotherContainer').load('/Home/RegularAjaxResource');

This would simply call a server resource (RegularAjaxResource in this case) and display it's returned data on an UI element with id anotherContainer

Ahmed
  • 11,063
  • 16
  • 55
  • 67
  • @7alwagy: totally prefer jQuery too...expect if you're relying on webform's Viewstates and Postbacks, then the non UpdatePanel option becomes quite painful...I've elaborated below – andy Jul 20 '09 at 05:51
7

I agree with 7alwagy, except just want to add an important point.

You have to use the UpdatePanel if you want to update/change controls AND still work within the Webforms Postback model of state control, in particular, Viewstate.

For example:

if you explicitly use JS to update the values of a DropDownList control on the client, and you're using the built in Webforms Postback model, the changes you've made won't be picked up.

Essentially, if you're relying on the built in Viewstates, then you have to use the UpdatePanel. You can technically not use it, but you'll really have to fight agaisnt the framework to get things done.

If you're not relying on Postbacks or Viewstates, then you totally don't need the UpdatePanel.

andy
  • 8,775
  • 13
  • 77
  • 122
3

I seriously cannot think of 1 advantage of using updatepanels. They are grief and i found that out the hard way.

They're usable only for the most trivial ajax effects and if you're going to do any data retrieval or database lookups they have a huge problem in scaling up. UpdatePanels are frustrating and not a long time I have shared the updatepanel grief here, here, here and here.

If that's not enough to convince you not to use updatepanel then nothing will.

Cyril Gupta
  • 13,505
  • 11
  • 64
  • 87
  • 2
    I read your posts and they were very weak. You only complained about using update panels but never explained why. Only one post mentioned something about wrapping a div in a table because you were having some issue. if you can't think of a single advantage then you don't know how to use them properly. They are not perfect but they have good uses if used properly. If your WebForm page depends on viewstate then they are pretty useful. – Tony_Henrich Aug 04 '13 at 08:14
1

I agree that update panel is evil and dangerous but in some cases you may want to use it, instead of other options.

  • The page has few asp.net controls, and less viewstate.
  • The page html is not too big.
  • The time is limited to finish the task.
  • The performance is not the first concern.
  • Want to keep the sate of controls with postbacks.
  • Have a lot of server side events you want to fire.
Amr Elgarhy
  • 66,568
  • 69
  • 184
  • 301
  • Disagree. I have universally found this to be a mistake. Once you start down that path with a simple project, you almost always have your hands tied to the technology because no one wants to pay for a re-write and every user asks "Can't you just _____________"? – Micah B. Sep 17 '12 at 19:23
1

Advantages:

  1. Easy to implement
  2. No need to write javascript in the client

Disadvantages

  1. Uses more bandwidth since all view states are transferred
  2. Element which is supposed to fire the ajax call should be inside the update panel. It is not practically possible all the time
  3. Data outside the update panel is not sent to the server which may be needed for further processing.
  4. In practice developer cannot pre-determine what all data is needed to include in the update panel
Beingnin
  • 2,288
  • 1
  • 21
  • 37