Accessing Properties of Dynamically added Web User Controls

Discussion in 'ASP .Net' started by Guest, May 6, 2005.

  1. Guest

    Guest 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).

    Guest, May 6, 2005
    1. Advertisements

  2. Guest

    Brock Allen Guest

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

    UserControl uc = LoadControl("foo.ascx");
    MyUC myuc = uc as MyUC;
    if (myuc != null)
    myuc.MyProp = 5; // etc...
    Brock Allen, May 6, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.