title: How to add controls dynamically when click button in asp.net?
body: <p>I'm trying to add controls dynamically </p>
  
  <p>Code:</p>
  
  <p>AddVisaControl.ascx</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AddVisaControl.ascx.cs" EnableViewState="false" Inherits="Pyramid.AddVisaControl" %&gt;
  &lt;%@ Register assembly="BasicFrame.WebControls.BasicDatePicker" namespace="BasicFrame.WebControls" tagprefix="BDP" %&gt;
  &lt;div id="divreg" runat="server"&gt;
  &lt;table id="tbl" runat="server"&gt;
  &lt;tr&gt;
    &lt;td class="style8"&gt; Visa Number:&lt;/td&gt;
    &lt;td class="style20"&gt;&lt;asp:TextBox ID="txtUser" Width="160px" runat="server"/&gt;&lt;/td&gt;
    &lt;td class="style22"&gt; Country Name:&lt;/td&gt;
    &lt;td class="style23"&gt;
  &lt;asp:DropDownList ID="dropCountry" Width="165px" runat="server"&gt;
  &lt;/asp:DropDownList&gt;&lt;/td&gt;
  &lt;/tr&gt;
   &lt;tr&gt;
   &lt;td class="style22"&gt; Type of Visa:&lt;/td&gt;
   &lt;td class="style23"&gt;
  &lt;asp:DropDownList ID="dropVisa" Width="165px" runat="server"&gt; &lt;/asp:DropDownList&gt;&lt;/td&gt;
  &lt;td class="style22"&gt; Type of Entry:&lt;/td&gt;
  &lt;td class="style23"&gt;
  &lt;asp:DropDownList ID="dropEntry" Width="165px" runat="server"&gt; &lt;/asp:DropDownList&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td class="style8"&gt;&amp;nbsp; Expiry Date&lt;/td&gt;
  &lt;td class="style20"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p></p>
  
  <p>.cs code:</p>
  
  <p>Below code is the problem when the first time I click add button it is adding controls properly but If I close the browser window and comes again and click the add button I got more controls</p>
  
  <pre><code>   static int i = 0;
      protected void addnewtext_Click(object sender, EventArgs e)
      {
          i++;
          for (int j = 0; j &lt;= i; j++)
          {
              AddVisaControl ac = (AddVisaControl)Page.LoadControl("AddVisaControl.ascx");
              PlaceHolder1.Controls.Add(ac);
              PlaceHolder1.Controls.Add(new LiteralControl("&lt;BR&gt;"));
          }
      }
  </code></pre>
  
  <p>In the below image If I click add more visa button I want to get another visa details</p>
  
  <p><img src="https://i.stack.imgur.com/wUKPi.png" alt="enter image description here"></p>
  
  <p>Any ideas? Thanks in advance</p>