Thanks for your help. I changed my code to:
MyControl c = (MyControl)Page.LoadControl(Request.ApplicationPat h +
"/User_Controls/website_design.ascx");
c.Item = "abc";
UserControlPlaceHolder.Controls.Add(c);
When I build the page, I get the following error messages:
The type or namespace name 'MyControl' could not be found (are you missing a
using directive or an assembly reference?)
The best overloaded method match for
'System.Web.UI.ControlCollection.Add(System.Web.UI .Control)' has some
invalid arguments
Argument '1': cannot convert from 'MyControl' to 'System.Web.UI.Control'
What am I doing wrong here?
Thanks,
Keith
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:ec**************@TK2MSFTNGP02.phx.gbl...
You already have a reference to the control in variable c. You just need
to typecast it to your type. One of the options:
MyControl c = (MyControl)Page.LoadControl(Request.ApplicationPat h +
"/User_Controls/website_design.ascx");
c.MyProperty = myValue;
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"keith" <kb******@dslextreme.comwrote in message
news:u6****************@TK2MSFTNGP02.phx.gbl...
>>I use this code to load a user control at runtime:
Control c = Page.LoadControl(Request.ApplicationPath +
"/User_Controls/website_design.ascx");
UserControlPlaceHolder.Controls.Add(c);
Immediately after loading the control, I need to set a property of the
user control.
I have tried various ways of directly referencing the control without
success. I have also tried using FindControl, but all I get is a null
value. Any suggestions?
Thanks,
Keith