Accessing Properties of Dynamically added Web User Controls

G

Guest

Thanks for your time.

I've created a web user control that has some properties available. I'm
able to add the control dynamically (at run time) with no
problem([placeholder].controls.add([control]). Is it possible to set
property values of a dynamically added web user control at run time? Can you
provide a link or code snippet?

I can do it for a typical web control (textbox, label, etc), but I can't
figure out how to do it for a web user control(ascx file type).

Thanks
 
B

Brock Allen

Yes you can, but you'll need to downcast the variable once you've called
LoadControl.

UserControl uc = LoadControl("foo.ascx");
MyUC myuc = uc as MyUC;
if (myuc != null)
{
myuc.MyProp = 5; // etc...
}
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top