473,406 Members | 2,894 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 create multiple instances of usercontrol in codebehind

I created a user conrolt in C# and want to create multiple instance (one by
one) of usercontrol onclick of button. if i hard code in .aspx page like

<%@ Register Src="~/UserControls/AddPhaseMilestone.ascx"
TagName="AddPhaseMilestone" TagPrefix="uc1" %>

<uc1:AddPhaseMilestone ID="AddPhaseMilestone1" EnableViewState="true"
runat="server" />

<uc1:AddPhaseMilestone ID="AddPhaseMilestone2" EnableViewState="true"
runat="server" />

<uc1:AddPhaseMilestone ID="AddPhaseMilestone3" EnableViewState="true"
runat="server" />

<uc1:AddPhaseMilestone ID="AddPhaseMilestone4" EnableViewState="true"
runat="server" />

it works fine. I have to do in codebehind using click event to button. Pls
do suggest me how to do that. I tried below mention code but it is not
solving my problem.

Control oControl = Page.LoadControl("~/UserControls/AddPhaseMilestone.ascx");

//oControl.ID = "fajkla";

//PlaceHolder1.Controls.Add(oControl);

//div.Controls.Add(oControl);

Page.Controls.Add(oControl);

pls suggest some alternative solutions also, if possible

Aug 28 '07 #1
1 3015
Padam wrote:
I created a user conrolt in C# and want to create multiple instance (one by
one) of usercontrol onclick of button. if i hard code in .aspx page like

<%@ Register Src="~/UserControls/AddPhaseMilestone.ascx"
TagName="AddPhaseMilestone" TagPrefix="uc1" %>

<uc1:AddPhaseMilestone ID="AddPhaseMilestone1" EnableViewState="true"
runat="server" />

<uc1:AddPhaseMilestone ID="AddPhaseMilestone2" EnableViewState="true"
runat="server" />

<uc1:AddPhaseMilestone ID="AddPhaseMilestone3" EnableViewState="true"
runat="server" />

<uc1:AddPhaseMilestone ID="AddPhaseMilestone4" EnableViewState="true"
runat="server" />

it works fine. I have to do in codebehind using click event to button. Pls
do suggest me how to do that. I tried below mention code but it is not
solving my problem.

Control oControl = Page.LoadControl("~/UserControls/AddPhaseMilestone.ascx");

//oControl.ID = "fajkla";

//PlaceHolder1.Controls.Add(oControl);

//div.Controls.Add(oControl);

Page.Controls.Add(oControl);

pls suggest some alternative solutions also, if possible
Hi Padam,
Can you just show/hide the control :)

Regards,
Petar Atanasov
http://a-wake.net
Aug 28 '07 #2

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

Similar topics

1
by: Alan Lambert | last post by:
I'm quite new to ASP.NET so please forgive me if this is a silly question but I'm completely stuck! I'm trying to dynamically add a UserControl to a web form. My control is in a file called...
4
by: Mat | last post by:
Hi, I am having a bit of a problem trying to access / set properties of a usercontrol from the parent codebehind. This is what I have so far.. simple.aspx <%@ Page...
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: Tim_Mac | last post by:
hi, i have an aspx page which dynamically loads a user control and adds it to a placeholder. the control is recreated and added to the placeholder for postbacks as well. the user control...
2
by: MLS | last post by:
The documentation on dynamic handlers comes across as abiguous. Perhaps somebody could help set me straight? I have a situation where I need to dynamically create several usercontrols of the...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
1
by: =?Utf-8?B?UGFkYW0=?= | last post by:
I created a webuser control (sample.ascx). I have to call this web user control to another with multiple instances. i.e. 1st Usr Control : Sample1.ascx 2nd Usr Control : Register...
2
by: jasinx | last post by:
When I run this code it creates a button on an .aspx page. When I click the button it seems to fire the events but I'm unable to capture them in the function in the ascx codebehind. Any help? Thank...
3
by: | last post by:
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...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.