Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Create User Controls dynamically

Reply
Thread Tools

Create User Controls dynamically

 
 
David Lozzi
Guest
Posts: n/a
 
      10-13-2005
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




 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      10-13-2005
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" <(E-Mail Removed)>
| 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: <#(E-Mail Removed)>
| 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
| dlozzi@(remove-this)delphi-ts.com
|
|
|
|
|

 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      10-19-2005
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: <#(E-Mail Removed)>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: http://www.velocityreviews.com/forums/(E-Mail Removed) (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: <(E-Mail Removed)>
| 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! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
| --------------------
| | From: "David Lozzi" <(E-Mail Removed)>
| | 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: <#(E-Mail Removed)>
| | 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
| | dlozzi@(remove-this)delphi-ts.com
| |
| |
| |
| |
| |
|
|

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Issues in ASP.NET 2.0 when dynamically loading user controls or asp.net web controls??? Bob Rock ASP .Net 1 09-17-2006 01:49 PM
Inserting Controls Dynamically - with Validators Also Added Dynamically Jeffrey Todd ASP .Net 1 06-02-2005 04:33 PM
using javascript in User controls to access server controls of the user control Faizan Ahmed ASP .Net Building Controls 1 01-04-2005 04:09 PM
using javascript in User controls to access server controls of the user control Faizan Ahmed ASP .Net Web Controls 1 01-04-2005 04:09 PM
How do I dynamically create user controls? David J. Berman ASP .Net 1 06-30-2003 07:24 PM



Advertisments