如何在按钮单击时动态添加带有asp控件的面板

时间:2014-06-24 08:20:00

标签: c# panel

我有一个内置asp.net控件的面板。 在每个AddNew链接按钮上单击我必须一次又一次添加此面板。我怎么能这样做?

由于

这是我的小组:

<asp:Panel ID="pBody" runat="server" CssClass="cpBody">
            <div class="field"> 
              <asp:TextBox runat='server' ID='txtNumber' MaxLength='12' CssClass='textBox'      Width="300px" /> 
              <asp:RequiredFieldValidator id="RequiredFieldValidatortxtNumber" runat="server" ControlToValidate="txtNumber" ErrorMessage="<%$ Resources:PleaseFillTheRequiredField %>" ForeColor="Red"></asp:RequiredFieldValidator> 
            </div> 
            <div class="label"> 
               <asp:Literal ID="litCurrentState" runat="server" Text="<%$ Resources:CurrentState %>" />:
               <span id="spanCurrentStateValid" runat="server" class="text-danger">*</span> 
            </div> 
            <div class="field"> 
              <asp:DropDownList ID="ddlCurrentState" runat="server" CssClass="textBox filter-textbox"   Width="300px"></asp:DropDownList>
              <asp:RequiredFieldValidator id="RequiredFieldValidatorCurrentState" runat="server"  ControlToValidate="ddlCurrentState" ErrorMessage="<%$ Resources:PleaseFillTheRequiredField %>" InitialValue="- Choose-" ForeColor="Red"> </asp:RequiredFieldValidator> 
            </div> 
            <div class="label"> 
               <asp:Literal ID="litDocumentPath" runat="server" Text="<%$Resources:DocumentPath %>" />: 
               <span id="spanDocumentPathValid" runat="server" class="text-danger">*</span>            </div> 
           <div class="field"> 
               <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
                  <Triggers> 
                      <asp:PostBackTrigger ControlID="UploadButton" /> 
                  </Triggers> 
                  <ContentTemplate>
                      <asp:FileUpload ID="fupDocumentPath" runat="server" Width="300px" /> 
                      <asp:Button runat="server" id="UploadButton" CausesValidation="false" text="Upload" onclick="UploadButton_Click" /> 
                      <asp:Label runat="server" id="StatusLabel" text="Upload status: " /><br /><br />          
                  </ContentTemplate> 
               </asp:UpdatePanel> 
        <asp:RequiredFieldValidator id="RequiredFieldValidatorDocumentPath" runat="server" ControlToValidate="fupDocumentPath" ErrorMessage="<%$ Resources:PleaseFillTheRequiredField %>" ForeColor="Red" Display="Dynamic"></asp:RequiredFieldValidator> 
        <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="#">Example</asp:HyperLink>
     </div> 
    </asp:Panel> 
    <asp:LinkButton runat="server" ID="lbtnAddNew">Add new</asp:LinkButton>

1 个答案:

答案 0 :(得分:1)

UserControl中定义面板,然后在按钮上单击以编程方式实例化您的控件并将其添加到视图中。