dynamically create multiple instance of usercontrol in codebehind

Discussion in 'ASP .Net Web Controls' started by Padam, Aug 28, 2007.

  1. Padam

    Padam Guest

    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);
     
    Padam, Aug 28, 2007
    #1
    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. Mat
    Replies:
    4
    Views:
    382
  2. =?Utf-8?B?UGFkYW0=?=
    Replies:
    1
    Views:
    1,464
    Petar Atanasov
    Aug 28, 2007
  3. thomson
    Replies:
    2
    Views:
    2,033
    thomson
    Mar 5, 2008
  4. Padam
    Replies:
    3
    Views:
    1,479
    Jens Wefer
    Aug 28, 2007
  5. 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
Loading...

Share This Page