User controls and LoadControl method

J

J055

Hi

I need to send parameters to a user control contructor. Is this what the
TemplateControl.LoadControl (Type, Object[]) is for? If so can someone show
me how to use it please?

This is my attempt so far but I get a MissingMethodException - Constructor
on type '*' not found. The control would be loaded twice anyway. Hopefully
you can see what I'm trying to achieve.

Control myCtrl = LoadControl("~/Controls/myCtrl.ascx");
PlaceHolder ph = (PlaceHolder)fv.FindControl("ph");
ph.Controls.Add(LoadControl(myCtrl.GetType(), new object[] { myobj }));
ph.Visible = true;

Many thanks
Andrew
 
L

Luke Zhang [MSFT]

Hello Andrew,

If you need to send parameters to a user control, you may consider created
customized public property for the user control, and set the property right
after you create/load it.

Sincerely,

Luke Zhang

Microsoft Online Community Support
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top