Saturday, March 24, 2012

UpdatePanel and Databind sync

Hello all,

Just wondering if anybody has a solution to this problem I am currently having:

Update Panel (A) containing a simple button and a database entry does a post back
Update Panel (B) containing a databind list and mode set to "always" also does a post back

But Panel B refreshes before Panel A has finished inserting the recordinto the database. Therefore the new entry never shows up unless yourefresh the page once more.

Is there a way around it so that Update Panel B waits for Panel A to finish its execution?What you could do is set Panel (B) 's mode to 'conditional' and then when the button in Panel(A) raises the click event, call Panel(B)'s Update() method.

As for keeping Panel(B)'s mode at 'automatic' I don't know if there is a way without trying some sort of syncing or polling.
Thanks for the reply, is there a way from the code behind of a customuser control within an update panel to get the reference to the updatepanel (B) on the content page?

For some odd reason although on my master details page or my contentpage where these update Panels are located, Page.Controls.Count orsomething similar returns me only 1.

Any thoughts?

Many thanks
Hmmmmm.

Yes there are ways but without knowing your design it's hard to say which is best. Some ways are easier than others but will create a coupled design...others are elegant but time consuming to implement.

Some of the ways to get a reference to the other panel are:
Implement a recursive FindControl(Control controlToSearch) passing in the reference to the Page as the first parameter (yuck...but reasonably easy to implement). You will also need to either hard code the ID of the second update panel in the UserControl or add a property to the UserControl to take in the ID of the UpdatePanel; OR

Excellent post, will let you know on Monday as to how things went :)

No comments:

Post a Comment