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?
views:
2258answers:
5The advantages of the update panel are it's easy to use, but every time the update panel is triggered a the full page is rendered on the server. so it might help reducing some traffic if its compared to the classic postback. The alternative is doing it in js, with some WS/webMethods on the server side that will return some Json/HTML.
Advantages:
- Easy to use and configure (Well, I don't know of any other advantage!)
Disadvantages:
See here and here
Now for the best part, the alternatives:
User 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!
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
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.
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.
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.