Create User Controls dynamically

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Create User Controls dynamically

    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
    [email]dlozzi@(remove-this)delphi-ts.com[/email]




    David Lozzi Guest

  2. Similar Questions and Discussions

    1. Dynamically created user controls
      In ASP.Net, I am working with some in-house software that dynamically creates a form based on rows in a database table. For example, most pages...
    2. Dynamically create controls with non-hierarchical IDs
      You could add a Name attribute to the control and use GetElementsByName to find it. Dale "Simon Wallis"...
    3. dynamically adding user controls
      I have a web form that has a button called "Add Blank Row". Every time this button is pressed a new "blank row" user control should be added to the...
    4. Dynamically create controls from a network directory tree
      I'm trying to create a search page with msIndex service and i want the user to be able to select the directories they would like to search within....
    5. How do I dynamically create user controls?
      Thanks for any help...! My error is: Object reference not set to an instance of an object. Here's the setup: I have made a user control...
  3. #2

    Default RE: Create User Controls dynamically

    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! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    --------------------
    | From: "David Lozzi" <DavidLozzi@nospam.nospam>
    | 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: <#qGmvg7zFHA.908@tk2msftngp13.phx.gbl>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.comcast.net 24.63.42.200
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5788
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    |
    | 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
    | [email]dlozzi@(remove-this)delphi-ts.com[/email]
    |
    |
    |
    |
    |

    Steven Cheng[MSFT] Guest

  4. #3

    Default RE: Create User Controls dynamically

    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! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | X-Tomcat-ID: 178280068
    | References: <#qGmvg7zFHA.908@tk2msftngp13.phx.gbl>
    | MIME-Version: 1.0
    | Content-Type: text/plain
    | Content-Transfer-Encoding: 7bit
    | From: [email]stcheng@online.microsoft.com[/email] (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.datagridc ontrol
    | Message-ID: <zo5RVx9zFHA.2352@TK2MSFTNGXA01.phx.gbl>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | Lines: 53
    | Path: TK2MSFTNGXA01.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridc ontrol: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! [url]www.microsoft.com/security[/url]
    | (This posting is provided "AS IS", with no warranties, and confers no
    | rights.)
    |
    | --------------------
    | | From: "David Lozzi" <DavidLozzi@nospam.nospam>
    | | 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: <#qGmvg7zFHA.908@tk2msftngp13.phx.gbl>
    | | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | | NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.comcast.net 24.63.42.200
    | | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
    | | Xref: TK2MSFTNGXA01.phx.gbl
    | microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5788
    | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | |
    | | 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
    | | [email]dlozzi@(remove-this)delphi-ts.com[/email]
    | |
    | |
    | |
    | |
    | |
    |
    |

    Steven Cheng[MSFT] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139