D'Arcy from Winnipeg
Solution Architecture, Business & Entrepreneurship, Microsoft, and Adoption

AJAX Update Panels - Like Transformers, More Than Meets The Eye

Tuesday, September 4, 2007 3:52 PM

We ran into a snag with our current web app project. We have a page with an update panel, which has user controls within it that contain more update panels. We're trying to get the user-control update panels to fire without the main page going through its page_load event, but not having any luck.

Interestingly, there's a way to enable partial post backs...but its a little decieving.

By default, you can set an update panel to run in two update modes: Conditional or Always. Always is the default, and means that any controls that trigger a postback will cause an async call. However if you specify Conditional, then you can specify exactly which control will cause your udpate panel to update.

You can also set "Children as Triggers" to false, which will keep child controls (including those from a nested panel) from refreshing the Update Panel.

So to recap: Two Update Panels, one nested in another; Parent Update Panel has Update Mode set to Conditional and Children As Triggers set to False.

This means that if I click on a button in my nested Update Panel, only that panel should be updated...and that's what you see in the browser: the nested update panel updates a label with the current time while the parent does nothing.

But there's something else behind the scenes going on. If you put breakpoints into the Page_Load of the page for instance, you'll notice that even though the parent Update Panel doesn't visibly update, the Page_Load still fires. So if you have any code assigning session variables, retrieving data, etc. in your Page_Load, that will still execute.

Now, there's obviously a point where you say "Well, you should make sure you're not doign stupid things in your page load then", and you'd be right. But at the same time, you need to remember that just because the screen doesn't update doesn't mean that things aren't happening at the code behind level, and you have to factor that in when you design your presentation layer.

Sorry about this post...I wanted to capture the essence of the issue, but words really don't communicate it well. Look for a short web-cast on this in the near future...I'm curious to try and find a solution to this as well.

D




Feedback

# re: AJAX Update Panels - Like Transformers, More Than Meets The Eye

We run into this problem of as well, it would be nice if an update panel could only hit the control its updating on the web server and save us all a lot of trouble. Our solution was to switch to web services, even though they take longer to make the result is always better 9/5/2007 4:40 AM | Max

# re: AJAX Update Panels - Like Transformers, More Than Meets The Eye

Could you not just check for IsInAsyncPostBack() in the page load and exit if you're in it? I do this all the time (not sure if it's the best way to do it)

-Matt 9/5/2007 1:18 PM | Matt

# re: AJAX Update Panels - Like Transformers, More Than Meets The Eye

Thanks Matt...that could be what we were looking for...

D 9/5/2007 3:03 PM | D'Arcy from Winnipeg

# re: AJAX Update Panels - Like Transformers, More Than Meets The Eye

The UpdatePanel will always cause the full page life cycle. (Though you can short circuit the process with tricks like Matt suggested). This is the cost of using the simplistic UpdatePanel.

For targeted processing you're going to have to move under the hood and set up web services.

This screen cast might help.
http://asp.net/learn/ajax-videos/video-79.aspx 9/21/2007 1:32 AM | Justin Kohnen

# re: AJAX Update Panels - Like Transformers, More Than Meets The Eye

Yeah, we ended up going with the targeted processing...although web services isn't your only option.

You can also set-up web-methods in a class that act just like a web-service would, but without having to create and deploy a full web-service. The tradeoff is that only your website can access the method as opposed to multiple sources accessing the web-service, but if you don't require multiple source access then its a no-brainer to utilize.

D 9/21/2007 1:41 AM | D'Arcy from Winnipeg

Post a comment