Create User Controls dynamically

Discussion in 'ASP .Net Datagrid Control' started by David Lozzi, Oct 13, 2005.

  1. David Lozzi

    David Lozzi Guest

    Howdy,

    I have a user control that needs to be displayed X amount of times on one
    page. How is this done? I was thinking of putting it into a datagrid, which
    would work, but is there a better way?

    Thanks!

    --
    David Lozzi
    Web Applications Developer
    dlozzi@(remove-this)delphi-ts.com
    David Lozzi, Oct 13, 2005
    #1
    1. Advertising

  2. Hi David,

    Welcome to ASPNET newsgroup.
    As for dynamically creating UserControl on asp.net web page. In addition to
    using Template DAtaBound control (as DataGrid, Repeater....), we can also
    use Page.LoadControl to load control instance and add them into a certain
    container control on the page. For example:

    ==================
    private void Page_Load(object sender, System.EventArgs e)
    {
    ..........
    for(int i=0;i<1000;i++)
    {
    Control ctrl = Page.LoadControl("~/uc/MyUsercontrol.ascx");
    ctrl.ID = "myuc_" +i;
    MyPanel.Controls.Add(ctrl);
    }
    }


    BTW, dynamically loading lots of usercontrols and adding into page's
    control structure will cause performance issue especially when the
    usercontrol is not simple one.

    Hope helps. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    --------------------
    | From: "David Lozzi" <>
    | Subject: Create User Controls dynamically
    | Date: Thu, 13 Oct 2005 01:37:16 -0400
    | Lines: 16
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
    | X-RFC2646: Format=Flowed; Original
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
    | Message-ID: <#>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.comcast.net 24.63.42.200
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridcontrol:5788
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    |
    | Howdy,
    |
    | I have a user control that needs to be displayed X amount of times on one
    | page. How is this done? I was thinking of putting it into a datagrid,
    which
    | would work, but is there a better way?
    |
    | Thanks!
    |
    | --
    | David Lozzi
    | Web Applications Developer
    | dlozzi@(remove-this)delphi-ts.com
    |
    |
    |
    |
    |
    Steven Cheng[MSFT], Oct 13, 2005
    #2
    1. Advertising

  3. Hi David,

    Have you got any further progress on this issue. or does the suggestions in
    my last reply helps a little? If there're anything else we can help, please
    feel free to post here. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | X-Tomcat-ID: 178280068
    | References: <#>
    | MIME-Version: 1.0
    | Content-Type: text/plain
    | Content-Transfer-Encoding: 7bit
    | From: (Steven Cheng[MSFT])
    | Organization: Microsoft
    | Date: Thu, 13 Oct 2005 09:55:44 GMT
    | Subject: RE: Create User Controls dynamically
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | Lines: 53
    | Path: TK2MSFTNGXA01.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridcontrol:5789
    | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
    |
    | Hi David,
    |
    | Welcome to ASPNET newsgroup.
    | As for dynamically creating UserControl on asp.net web page. In addition
    to
    | using Template DAtaBound control (as DataGrid, Repeater....), we can also
    | use Page.LoadControl to load control instance and add them into a certain
    | container control on the page. For example:
    |
    | ==================
    | private void Page_Load(object sender, System.EventArgs e)
    | {
    | .........
    | for(int i=0;i<1000;i++)
    | {
    | Control ctrl = Page.LoadControl("~/uc/MyUsercontrol.ascx");
    | ctrl.ID = "myuc_" +i;
    | MyPanel.Controls.Add(ctrl);
    | }
    | }
    |
    |
    | BTW, dynamically loading lots of usercontrols and adding into page's
    | control structure will cause performance issue especially when the
    | usercontrol is not simple one.
    |
    | Hope helps. Thanks,
    |
    | Steven Cheng
    | Microsoft Online Support
    |
    | Get Secure! www.microsoft.com/security
    | (This posting is provided "AS IS", with no warranties, and confers no
    | rights.)
    |
    | --------------------
    | | From: "David Lozzi" <>
    | | Subject: Create User Controls dynamically
    | | Date: Thu, 13 Oct 2005 01:37:16 -0400
    | | Lines: 16
    | | X-Priority: 3
    | | X-MSMail-Priority: Normal
    | | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
    | | X-RFC2646: Format=Flowed; Original
    | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
    | | Message-ID: <#>
    | | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | | NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.comcast.net 24.63.42.200
    | | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
    | | Xref: TK2MSFTNGXA01.phx.gbl
    | microsoft.public.dotnet.framework.aspnet.datagridcontrol:5788
    | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | |
    | | Howdy,
    | |
    | | I have a user control that needs to be displayed X amount of times on
    one
    | | page. How is this done? I was thinking of putting it into a datagrid,
    | which
    | | would work, but is there a better way?
    | |
    | | Thanks!
    | |
    | | --
    | | David Lozzi
    | | Web Applications Developer
    | | dlozzi@(remove-this)delphi-ts.com
    | |
    | |
    | |
    | |
    | |
    |
    |
    Steven Cheng[MSFT], Oct 19, 2005
    #3
    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. David J. Berman

    How do I dynamically create user controls?

    David J. Berman, Jun 25, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    4,406
    David J. Berman
    Jun 30, 2003
  2. Jeffrey Todd
    Replies:
    1
    Views:
    4,101
    Peter Blum
    Jun 2, 2005
  3. Bob Rock
    Replies:
    1
    Views:
    625
    Cowboy \(Gregory A. Beamer\)
    Sep 17, 2006
  4. Faizan Ahmed
    Replies:
    1
    Views:
    281
    John Saunders
    Jan 4, 2005
  5. Faizan Ahmed
    Replies:
    1
    Views:
    358
    John Saunders
    Jan 4, 2005
Loading...

Share This Page