473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

dynamically loading usercontrol

Hello all,

I have a UserControl that renders some HTML content. I now need to
dynamically load and render "n" instances of this usercontrol on a host aspx
page inside a panel control based upon user input of "n". Any ideas how I
can do this?

TIA!
Jan 23 '08 #1
3 1291
You need to use a databound control, perhaps a repeater, that will be bound
to a datasource, perhaps an array, containing all instances of the user
control.

Have some code that will creat an array myControls[] based on the user
input. Then do
myRepeater.DataSource = myControls;
myRepeater.DataBind();

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<pa***@community.nospamwrote in message
news:e$**************@TK2MSFTNGP02.phx.gbl...
Hello all,

I have a UserControl that renders some HTML content. I now need to
dynamically load and render "n" instances of this usercontrol on a host
aspx page inside a panel control based upon user input of "n". Any ideas
how I can do this?

TIA!

Jan 23 '08 #2
Howdy,

Use Repeater or DataList:

-- aspx code --
<asp:Repeater runat="server" ID="dynamicControls">
<ItemTemplate>
<uc1:myUserControl runat="server" ID="myUserControl"/>
</ItemTemplate>
</asp:Repeater>
-- c# code beside --
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int rowCount = 10;
myRepeater.DataSource = new int[rowCount];
myRepeater.DataBind();
}
}

Hope it helps
--
Milosz
"pa***@community.nospam" wrote:
Hello all,

I have a UserControl that renders some HTML content. I now need to
dynamically load and render "n" instances of this usercontrol on a host aspx
page inside a panel control based upon user input of "n". Any ideas how I
can do this?

TIA!
Jan 23 '08 #3
OK,

Thanks for the tip. Now, what if I need to set custom properties on my
usercontrol. Is that possible?

TIA!

"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:B8**********************************@microsof t.com...
Howdy,

Use Repeater or DataList:

-- aspx code --
<asp:Repeater runat="server" ID="dynamicControls">
<ItemTemplate>
<uc1:myUserControl runat="server" ID="myUserControl"/>
</ItemTemplate>
</asp:Repeater>
-- c# code beside --
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int rowCount = 10;
myRepeater.DataSource = new int[rowCount];
myRepeater.DataBind();
}
}

Hope it helps
--
Milosz
"pa***@community.nospam" wrote:
>Hello all,

I have a UserControl that renders some HTML content. I now need to
dynamically load and render "n" instances of this usercontrol on a host
aspx
page inside a panel control based upon user input of "n". Any ideas how I
can do this?

TIA!

Jan 23 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark Stokes | last post by:
Hi guys, I have seen various messages on this front, but none specific to my requirement. I have an application that dynamically loads a user control and displays it on the page during the...
1
by: Sundaresan | last post by:
I've a form where I load two user controls dynamically. User Control-1 has a no.of dropdowns and based on the selection I typically populate a datagrid in the user control-2, Also the I could...
2
by: Eric | last post by:
I'm trying to dynamically load a user control using on the .NET framework (not Visual Studio). The control was designed in Visual Studio and is named: Disable.ascx The first line is: <%@...
1
by: Josh | last post by:
Hi Guys, I have been having a big problem with trying to pass parameters into a user control when the user control is dynamically loaded into a placholder. I am developing in c#. I have get...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
5
by: darrel | last post by:
I'm still a bit stumped on how to load a usercontrol, and then pass a property value (or variable value) to it. Here's what I'm using to load the UC: localCUstomControl.ascx.vb...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
2
by: A.Wussow | last post by:
Hi Everybody, i want to load dynamically content from some user controls (with forms, or some data-controls) using atlas. So i use an UpdatePanel for loading the user control into a placeholder....
0
by: Jesper Lund Stocholm | last post by:
I have problems with sending javascript to the client from a dynamically loaded usercontrol. I have a single page that dynamically loads controls into a table cell in a HTML-table. For one of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.