Solved

Dynamic UserControls and delegates

Posted on 2004-10-27
464 Views
Last Modified: 2008-03-10
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?
       
0
Question by:awiinc
    7 Comments
     
    LVL 1

    Accepted Solution

    by:
    just a comment: may be through reflection?
    0
     
    LVL 2

    Author Comment

    by:awiinc
    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
    0
     
    LVL 1

    Expert Comment

    by:EugeneTrukhin
    nice, it is good to know!
    0
     
    LVL 2

    Author Comment

    by:awiinc
    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.
    0
     
    LVL 1

    Expert Comment

    by:EugeneTrukhin
    i think moderator can delete this topic.
    0
     
    LVL 1

    Expert Comment

    by:EugeneTrukhin
    or u can award yourself :)
    0
     
    LVL 2

    Author Comment

    by:awiinc
    Can he delete and award you 100 points for responding?
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Want to pick and choose which updates you receive? Feel free to check out this quick video on how to manage your email notifications.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now