Link to home
Start Free TrialLog in
Avatar of awiinc
awiinc

asked on

Dynamic UserControls and delegates

How does one gain access to delegate within a dynamically loaded usercontrol.  Here is short snippet of code:

        Dim ctlControl As UserControl
        ctlControl = LoadControl("~/FolderName/TomsTree.ascx")
        PlaceHolder1.Controls.Add(ctlControl)

        ctlControl = LoadControl("~/FolderName/MyDataGrid.ascx")
        PlaceHolder1.Controls.Add(ctlControl)

TomsTree has a delegate that needs to communicate with MyDataGrid when an event occurs.  This works perfectly if I declare the controls at design time...but how would I add an event handler and addressof to dynamically loaded controls such as this?
       
ASKER CERTIFIED SOLUTION
Avatar of EugeneTrukhin
EugeneTrukhin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of awiinc
awiinc

ASKER

Thank you Eugene, but I did figure it out by finding a control and then referencing the event: see below.

Dim obj1 As ucWithDelegate = CType(PlaceHolder1.FindControl("NameOfControlToFind1"),ucWithDelegate)
Dim obj2 As uclisteningforDelegate = CType(PlaceHolder1.FindControl("NameOfControlToFind2"), uclisteningforDelegate)
AddHandler obj1.CategoryChanged, AddressOf obj2.CategoryChanged
nice, it is good to know!
Avatar of awiinc

ASKER

How do I award EugeneTrukhin 100 points for responding.  I would like to delete this question from ASP.NET since I have figured the problem out without receiving an answer.  If this is not possible then just award Eugene all 250 points.
i think moderator can delete this topic.
or u can award yourself :)
Avatar of awiinc

ASKER

Can he delete and award you 100 points for responding?