Groups | Blog | Home
all groups > asp.net > august 2007 >

asp.net : dynamically create multiple instances of usercontrol in codebehind


Padam
8/27/2007 10:12:02 PM
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
Petar Atanasov
8/28/2007 12:00:00 AM
[quoted text, click to view]

Hi Padam,
Can you just show/hide the control :)

Regards,
Petar Atanasov
AddThis Social Bookmark Button