Accessing Properties of Dynamically added Web User Controls

Discussion in 'ASP .Net' started by =?Utf-8?B?QnJpYW4=?=, May 6, 2005.

  1. 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
     
    =?Utf-8?B?QnJpYW4=?=, May 6, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?QnJpYW4=?=

    Brock Allen Guest

    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



    > 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
    >
     
    Brock Allen, May 6, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeffrey Todd
    Replies:
    1
    Views:
    4,123
    Peter Blum
    Jun 2, 2005
  2. =?Utf-8?B?ZG90bmV0dGVzdGVy?=

    Accessing values of dynamically added controls on Postback

    =?Utf-8?B?ZG90bmV0dGVzdGVy?=, Jul 14, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    489
    Eliyahu Goldin
    Jul 14, 2005
  3. David Hubbard
    Replies:
    2
    Views:
    631
    David Hubbard
    Jan 17, 2006
  4. keithb
    Replies:
    3
    Views:
    2,746
    keithb
    May 7, 2006
  5. William Manring

    Accessing Dynamically added controls after postback

    William Manring, Jun 26, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    152
    Tim Boland
    Jun 26, 2003
Loading...

Share This Page