views:

569

answers:

2

First off, my Environment: VB.NET .NET 2.0 AJAX Update Panels also used around webpart zones. I have a masterpage and default page. Default page has WPM and two Zones. each webpart is just a shell and a usercontrol is used for A & B

I have two webparts, A & B. (Usercontrols)- A has a number of buttons. B has a listbox & Subs which populate the listbox and refresh the UpdatePanel that also sits (inside the webpart B) wrapping the listbox. I want to click a button in webpart A and it fires a sub in webpart B called 'Public Sub FillList()' I cant seem to workout how to do this. I have looked up webpart connects and I understand that I can pass properties which is fine, but I want to call subs/fire events.

Thanks in advance!

+1  A: 

This sounds like a case for "event bubbling".

Event bubbling allows a constituent control of some container to have it's events "bubbled" or raised up to be handled by the parent (container) control.

Your button control in Webpart A can have the following code within it's click event:

RaiseBubbleEvent(Me, args)

where args is some custom type deriving from System.EventArgs. This will then raise (or "bubble") the event (with your custom args) on the parent container (in your case the UserControl itself). This is handled within the following event on the parent container:

Protected Overrides Function OnBubbleEvent(ByVal source As Object, ByVal args As System.EventArgs) As Boolean

This can be repeated up the containment hierarchy within your webpage (with the page being the ultimate container). Once this event has reached a container that is the parent of both of your usercontrols (A & B), you can then call public methods on UserControl B from within the code for the parent container, passing in the custom eventargs if you wish.

CraigTP
A: 

I know its a bit dirty but I found a solution which kinda works:

MyControlThatNeedsUpdated grid = (MyControlThatNeedsUpdated)FindControlRecursive(Page, "MyControlThatNeedsUpdated"); grid.updateList();

private Control FindControlRecursive(Control root, string ControlType) { if (root.GetType().Name == ControlType) { return root; }

foreach (Control c in root.Controls)
{
    Control t = FindControlRecursive(c, ControlType);
    if (t != null)
    {
        return t;
    }
}

return null;

}

The method I call is 'updateList()'

JamesM