Wednesday, March 21, 2012

Partial Page Post Backs - Am I doing this right?

Hi,

This may seem pretty basic, but I'm teaching myself AJAX and I have a question about handling partial page post backs.

I have a page with three update panels. Each is triggered by a different event (two use drop down lists, one uses a radio button group). In my page load event, I first check 'ScriptManager1.IsInAsyncPostBack' to see if I have an AJAX post back. Then I check the value of 'ScriptManager1.AsyncPostBackSourceElementID' to determine which control created the post back. That result determines which block of code my program runs.

Is this the correct way to code a page with multiple partial page post backs? It makes sense to me, but I'd like to know that I am using the correct procedure.

Thanks for your help!

That's one way to do it, and will generally work.

You might consider something more directly event driven though, to make it easier to write/maintain. You can set those dropdowns to AutoPostBack and then handle their OnSelectedIndexChanged event the same way you normally would in a non-AJAX situation. This has the added benefit of degrading gracefully back to regular postbacks when AJAX isn't available on the client, which is a good thing to always keep in mind.

No comments:

Post a Comment