Call Base Class Method from Dynamic User Control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rsdev
    New Member
    • Jul 2007
    • 149

    Call Base Class Method from Dynamic User Control

    I've been reading up on delegates and BubbleEvents but this doesn't seem to be the answer to my simple problem.

    I have a method in my base class which I would like to call from a dynamically loaded user control after it has executed some other code.

    The method in my base class cannot be a static method (making it accessible to my user control) because it relies on other methods in the base class.

    Do I need to create a delegate for this method or a bubble event?

    Can somebody please point me in the right direction.
  • rsdev
    New Member
    • Jul 2007
    • 149

    #2
    I've read tons of literature and consulted my pro c#/ASP.NET books.

    I have this code in my user control.

    Code:
    public event EventHandler BubbleClick;
            protected void OnBubbleClick(EventArgs e)
            {
                if (BubbleClick != null)
                {
                    BubbleClick(this, e);
                }
            }
    When I load the control dynamically I want to add a new EventHandler to the user control.

    But BubbleClick is not a definition of UserControl so how do I assign an EventHandler to it?

    Totally stumped. Here's the bit that's not working.

    Code:
    while (i < compLength)
                {
                    string compPath = "_components/" + compType[i].Type + ".ascx";
                    UserControl compControl = (UserControl)Page.LoadControl(compPath);
                    compControl.ID = Convert.ToString(compType[i].CompId);
                    //PlaceHolder plcName = (PlaceHolder)Master.FindControl("MainContent").FindControl("PlaceHolderName" + compType[i].PlaceHolder.ToString()); //Find all PlaceHolders - names PlaceHolderName0, PlaceHolderName1...
                    PlaceHolder plcName = (PlaceHolder)findControl("PlaceHolderName" + compType[i].PlaceHolder.ToString(), Master);
                    plcName.Controls.Add(compControl);
                    if (compControl.ID == "1")
                    {
                       
                       compControl.BubbleClick += new EventHandler(BtnCloseEditMode_Click);
                    }
                    i++;
                }

    Comment

    • rsdev
      New Member
      • Jul 2007
      • 149

      #3
      The problem with the above code is that BubbleClick is not a definition of UserControl. So how do I declare this?

      Your help would be greatly appreciated.

      Comment

      Working...