Reputation: 175583
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!
Upvotes: 4
Views: 5464
Reputation: 416
instantuate both view panels to a third presenter class, Then let the presenter class control both views. for example:
You could just pass over what you need the 'middle class' to do its job for example, in your main you could have;
PresenterClass.AttachInterface(mIOrder);
PresenterClass.DoSomeCalulation();
PresenterClass.drawPanel(1);
PresenterClass.AttachInterface(mIOtherOrder);
PresenterClass.DoSomeCalulation();
PresenterClass.drawPanel(2);
each view will have its own controls. So many differant ways you could do this.. alternitivly you could use the middle class to instantuate both your panels then in each of your panels you could have 'get methods' to retrive the data for processing.
Upvotes: 0
Reputation: 12768
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.
Upvotes: 0
Reputation: 52178
This is a good technique if you want to refresh updatepanel from client side Javascript.
Upvotes: 0
Reputation: 151
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.
Upvotes: 3
Reputation: 1135
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.
Upvotes: 2