title: How can I add a new dynamic control on button click?
body: <p>When I click btnGDynamicCont I want to load the first set of controls, then on each further click of that button, add a new control (textbox) alongside the other ones, so each time it is clicked I am adding a new textbox across state.</p>
  
  <p>Do you know where I should add the creation of the new textbox in order to keep it after each postback?</p>
  
  <pre><code>{
      protected void Page_Load(object sender, EventArgs e)
      {
          if (Convert.ToString(ViewState["Generated"]) == "true")
              GenerateDynamicControls();
  
      }
  
      public void GenerateDynamicControls()
      {
          TextBox txtDynamic = new TextBox();
          txtDynamic.ID = "txtDynamic";
          txtDynamic.Text = "Dynamic TextBox";
          Page.Form.Controls.Add(txtDynamic);
  
          TextBox txtDynamic2 = new TextBox();
          txtDynamic2.ID = "txtDynamic2";
          txtDynamic2.Text = "Dynamic Textbox";
          Page.Form.Controls.Add(txtDynamic2);
  
      }
  
      protected void btnGDynamicCont_Click1(object sender, EventArgs e)
      {
          if (Convert.ToString(ViewState["Generated"]) != "true")
          {
              GenerateDynamicControls();
              ViewState["Generated"] = "true";
          }
          else
          {
              Response.Write("&lt;h2&gt;Controls are already exist in page&lt;/h2&gt;");
  
          }
      }
  }
  </code></pre>
  
  <p>}</p>