Whenever I give a presentation on ASP.NET AJAX, one of the features that impresses is the Update Panel. It makes it dead simple to add AJAX functionality to an existing ASP.NET website. Got some complex server-side logic (like a Gridview control) that you’d like to execute via AJAX without refreshing the page? Just wrap it in an Update Panel and walla… you’ve got an AJAX-ified page!
But that great simplicity comes with a cost. That being said, you should understand what’s involved and what’s going on under the covers with the Update Panel before you make a decision whether or not to use it. The Update Panel works by making an asynchronous post-back to the current ASPX page. On the server, the entire ASP.NET page life-cycle executes, including any & all complex logic you have. The only difference is that the server only sends back the portion of the HTML response that fits inside the Update Panel.
Dave Ward does a good job of explaining the costs here.
Simply put, if you are doing a simple operation that only brings back a small amount of information from the server to update the page in an AJAX operation, then don’t use the Update Panel. Use the MS AJAX Library to make a call to a web service instead as noted in Dave’s post.
Now, perhaps I’ve been committing a faux pas when demonstrating the Update Panel during my talks on ASP.NET AJAX? You see, the sample I always use is exactly the one Dave shows as a BAD example of using the Update Panel! I typically just update the current date & time inside and outside of the panel to show how it works.
I don’t think I’m going to change that demo, because it’s simple and allows the audience to focus on the features & functionality of the update panel without introducing other complexities into the demo. However, I have been clear and prescriptive in letting people know that using the Update Panel for this simple update the the date & time scenario is like using a sledgehammer to hit a needle. From a performance perspective, making AJAX calls to web services are the way to go for this scenario.
If you do use Update Panels, Dave has another post with tips how to avoid some common pitfalls that can lead to performance issues.