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. Advertisements

  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. Advertisements

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. Christian
    Replies:
    2
    Views:
    2,222
    Christian Cambier
    Jul 15, 2003
  2. Rick Spiewak
    Replies:
    1
    Views:
    425
    Rick Spiewak
    Jul 24, 2003
  3. Christian
    Replies:
    0
    Views:
    467
    Christian
    Jul 21, 2003
  4. Andreas Klemt
    Replies:
    3
    Views:
    1,005
    Natty Gur
    Aug 28, 2003
  5. Mike Levin
    Replies:
    0
    Views:
    393
    Mike Levin
    Dec 11, 2003
  6. Chris

    a simple webusercontrol ??

    Chris, May 17, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    535
    Andrea Williams
    May 24, 2004
  7. Arun

    WebUserControl and JavaScript

    Arun, Jul 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,936
  8. =?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,727
    Brock Allen
    May 28, 2005
Loading...