title: Adding Textbox at runtime in Asp.net
body: <p>in.aspx page</p>
  
  <pre><code>&lt;form id="MyForm" method="post" runat="server"&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"&gt;
      &lt;asp:Panel ID="Panel1" runat="server"&gt;
      &lt;asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /&gt;
      &lt;/asp:Panel&gt;  
  &lt;/asp:Content&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>in code behind .cs file</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
          if (!Page.IsPostBack)
          {
              //Remove the session when first time page loads.
              Session.Remove("clicks");
          }
  
      }
  
      protected void Button1_Click(object sender, EventArgs e)
      {
          int rowCount = 0;
  
          //initialize a session.
          rowCount = Convert.ToInt32(Session["clicks"]);
  
          rowCount++;
  
          //In each button clic save the numbers into the session.
          Session["clicks"] = rowCount;
  
  
          //Create the textboxes and labels each time the button is clicked.
          for (int i = 0; i &lt; rowCount; i++)
          {
  
              TextBox TxtBoxU = new TextBox();
              TextBox TxtBoxE = new TextBox();
  
              Label lblU = new Label();
              Label lblE = new Label();
  
              TxtBoxU.ID = "TextBoxU" + i.ToString();
              TxtBoxE.ID = "TextBoxE" + i.ToString();
  
              lblU.ID = "LabelU" + i.ToString();
              lblE.ID = "LabelE" + i.ToString();
  
  
              lblU.Text = "User " + (i + 1).ToString() + " : ";
              lblE.Text = "E-Mail : ";
  
              //Add the labels and textboxes to the Panel.
              Panel1.Controls.Add(lblU);
              Panel1.Controls.Add(TxtBoxU);
  
              Panel1.Controls.Add(lblE);
              Panel1.Controls.Add(TxtBoxE);
  
  
          }
      }
  </code></pre>