views:

1774

answers:

4

I have some code that modifies a value that several controls in other update panels are bound to. When this event handler fires, I'd like it to force the other update panels to refresh as well, so they can rebind.

Is this possible?

Edit:

To clarify, I have an update panel in one user control, the other update panels are in other user controls, so they can't see each other unless I were to expose some custom properties and use findControl etc etc...

Edit Again:

Here is what I came up with:

public void Update()
{
    recursiveUpdate(this); 
}

private void recursiveUpdate(Control control)
{
    foreach (Control c in control.Controls)
    {
        if (c is UpdatePanel)
        {
            ((UpdatePanel)c).Update();
        }

        if (c.HasControls())
        {
            recursiveUpdate(c);
        }
    }
}

I had 3 main user controls that were full of update panels, these controls were visible to the main page, so I added an Update method there that called Update on those three.

In my triggering control, I just cast this.Page into the currentpage and called Update.

Edit:

AARRGGGG!

While the update panels refresh, it does not call Page_Load within the subcontrols in them...What do I do now!

+2  A: 

You can set triggers on the events in the update panel you want updated or you can explicitly say updatepanel.update() in the code behind.

Cptcecil
+2  A: 

What about registering a PostBackTrigger (instead of an AsyncPostBackTrigger) that will refresh every panel when a specific event fires.

Or add the trigger that already refreshes some UpdatePanels to the other UpdatePanels as well.

Dr Zimmerman
+1  A: 

This is a good technique if you want to refresh updatepanel from client side Javascript.

Gulzar
A: 

Page.DataBind() kicks off a round of databind on all child controls. That'll cause Asp.Net to re-evaluate bind expressions on each control. If that's insufficient, you can add whatever logic you want to make sure gets kicked off to an OnDataBinding or OnDataBound override in your usercontrols. If you need to re-execute the Page_Load event, for example, you can simply call it in your overridden OnDataBound method.

Jacob Proffitt