Dynamic WebUserControl

Discussion in 'ASP .Net Web Controls' started by rodchar, Apr 13, 2007.

  1. rodchar

    rodchar Guest

    hey all,
    i read in a book that you can load a webusercontrol dynamically without
    having to place it on the web form at design time but i can't seem to get it
    to work. here a snippet of the code from the book:

    UserControl uc;
    uc = (UserControl)this.LoadControl("mycontrol.ascx");
    this.form1.FindControl("form1").Controls.Add(uc);

    One thing i had to change from the example in the book was "UserControl", in
    the book it was actually the name of my webusercontrol as the Type but when i
    tried to type that in it wouldn't recognize it.

    And how do i get to my public properties if this is possible (i'm using c#
    code-behind btw).

    thanks,
    rodchar
    rodchar, Apr 13, 2007
    #1
    1. Advertising

  2. rodchar

    rodchar Guest

    Please let me be more specific:

    uc = (UserControl)this.LoadControl("mycontrol.ascx");

    how do i assign values to my properties of the user control once it is loaded?



    "rodchar" wrote:

    > hey all,
    > i read in a book that you can load a webusercontrol dynamically without
    > having to place it on the web form at design time but i can't seem to get it
    > to work. here a snippet of the code from the book:
    >
    > UserControl uc;
    > uc = (UserControl)this.LoadControl("mycontrol.ascx");
    > this.form1.FindControl("form1").Controls.Add(uc);
    >
    > One thing i had to change from the example in the book was "UserControl", in
    > the book it was actually the name of my webusercontrol as the Type but when i
    > tried to type that in it wouldn't recognize it.
    >
    > And how do i get to my public properties if this is possible (i'm using c#
    > code-behind btw).
    >
    > thanks,
    > rodchar
    rodchar, Apr 13, 2007
    #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. Simon Storr
    Replies:
    0
    Views:
    484
    Simon Storr
    Jul 14, 2003
  2. Christian
    Replies:
    2
    Views:
    2,032
    Christian Cambier
    Jul 15, 2003
  3. Rick Spiewak
    Replies:
    1
    Views:
    335
    Rick Spiewak
    Jul 24, 2003
  4. Christian
    Replies:
    0
    Views:
    358
    Christian
    Jul 21, 2003
  5. =?Utf-8?B?Um9iZXJ0IFdhcmQ=?=

    Dynamic WebUserControl in ASP.net 2.0

    =?Utf-8?B?Um9iZXJ0IFdhcmQ=?=, May 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,605
    Brock Allen
    May 28, 2005
Loading...

Share This Page