1

I have a panel with asp.net controls inside. On each AddNew linkbutton click I have to add this panel again and again. How can I do that?

Thanks

Here is my panel:

<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 Answer 1

1

Define the panel in a UserControl and then on the button click programmatically instantiate your control and add it to the view.

Sign up to request clarification or add additional context in comments.

1 Comment

can you please elaborate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.