Hello all,

I'm having a little melt-down trying to work out how to call a method of a dynamically loaded control...

My setup is this:

Admin.aspx
CustomControl.ascx

Admin.aspx has the following code to load CustomControl.ascx:

UserControl UC = (UserControl)LoadControl("~/admin_custom_controls/howComments.ascx");

        modulesPlaceHolder.Controls.Clear();
        modulesPlaceHolder.Controls.Add(UC);

CustomControl.ascx has a method:

public void initiate()
    { 
      getComments("All");
            getUsers();
    }

What I'm trying to do, is call the initiate() method from the Admin.aspx
Tried everything, and trawled the web for hours!!!
Help! :)

Cast it into the type that it is, not UserControl. You should be able to access it then.

I'm a tad confused... What type can a WebUserControl be cast to if not UserControl?
:confused:
I'm calling the control to be displayed and the control has some internal logic, which is controlled using the interface on that control. It's just that I need to call one of it's public methods from the parent page as I'm about to display it...

Cast it into the type that it is, not UserControl. You should be able to access it then.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.