User Control Problems, please advise...

G

Guest

I don't know, maybe I am a moron, which is probably closer to the case,
because I'm having a hard time firing methods from a dynamically loaded user
control. Here is what I'm doing:

1.) Loading the control into a panel using following code:
<code>pnlUserControl.Controls.Add(LoadControl ("userallergy.ascx"));</code>

Now, if I was to use the ClassName directive in my user control, how would I
then instantiate the object in my aspx page so I can use the user control's
user-defined methods? Some of the examples that I have found on the Web are
using in-line C#not the code behind, so it is a little confusing.
 
G

Guest

You can do either this
MyUserControl ctrl = LoadControl("userallergy.ascx") as MyUserControl;
if (ctrl != null)
{
pnlUserControl.Controls.Add(ctrl);
ctrl.UserControlMethod();
}

or
MyUserControl ctrl = pnlUserControl.FindControl("userallergy") as
MyUserControl;


Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top