Professional Web Applications Themes

dynamically create multiple instances of usercontrol in codebehind - ASP.NET Building Controls

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 ...

  1. #1

    Default 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

    Padam Guest

  2. #2

    Default Re: dynamically create multiple instances of usercontrol in codebehind

    Padam wrote: 

    This code is all right.
    Why is it not solving your problem?
    What is your problem?

    --

    Riki


    Riki Guest

  3. #3

    Default Re: dynamically create multiple instances of usercontrol in codebe

    It is not working when i create instances of user control in code behind.
    padam

    "Riki" wrote:
     
    >
    > This code is all right.
    > Why is it not solving your problem?
    > What is your problem?
    >
    > --
    >
    > Riki
    >
    >
    >[/ref]
    Padam Guest

  4. #4

    Default Re: dynamically create multiple instances of usercontrol in codebe

    you must also load dynamically usercontrols after a postback.
    Padam schrieb: 
    >> This code is all right.
    >> Why is it not solving your problem?
    >> What is your problem?
    >>
    >> --
    >>
    >> Riki
    >>
    >>
    >>[/ref][/ref]
    Jens Guest

Similar Threads

  1. Dynamically add instances in a PDF form
    By sziegler@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 5
    Last Post: December 14th, 03:49 PM
  2. dynamically add usercontrol
    By Snorre in forum ASP.NET Building Controls
    Replies: 4
    Last Post: February 24th, 03:01 PM
  3. Reach UserControl from ASPX codebehind?
    By Özden Irmak in forum ASP.NET Building Controls
    Replies: 3
    Last Post: June 30th, 02:46 PM
  4. multiple datagrids dynamically from the codebehind
    By DaveF in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: May 5th, 05:20 AM
  5. Adding Server Control dynamically in CodeBehind
    By Serge in forum ASP.NET Building Controls
    Replies: 3
    Last Post: September 23rd, 03:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139