Home All Groups Group Topic Archive Search About

User controls and LoadControl method

Author
3 Oct 2006 3:12 PM
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

Author
5 Oct 2006 7:10 AM
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.