dynamically create multiple instances of usercontrol in codebehind

Discussion in 'ASP .Net' started by =?Utf-8?B?UGFkYW0=?=, Aug 28, 2007.

  1. 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
     
    =?Utf-8?B?UGFkYW0=?=, Aug 28, 2007
    #1
    1. Advertising

  2. 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
     
    Petar Atanasov, Aug 28, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Padam
    Replies:
    3
    Views:
    1,479
    Jens Wefer
    Aug 28, 2007
  2. DaveF

    multiple datagrids dynamically from the codebehind

    DaveF, May 3, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    127
    Michael Tkachev
    May 5, 2004
  3. J055
    Replies:
    5
    Views:
    1,032
    Steven Cheng[MSFT]
    Dec 25, 2006
  4. santoshp

    Dynamically adding multiple instances of same usercontrol

    santoshp, May 30, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    225
    santoshp
    May 30, 2007
  5. Padam
    Replies:
    0
    Views:
    248
    Padam
    Aug 28, 2007
Loading...

Share This Page