Accessing Properties of Dynamically added Web User Controls

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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...
}

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
Back
Top