title: How Do I Insert Dynamically Created Textbox Values To Database
body: <p>Here is my code to create dynamical textboxes..I want to insert those values to database</p>
  
  <p>I need to insert the dynamically created textbox values to database.how can i do that..i am new to asp.net</p>
  
  <p>Markup:</p>
  
  <pre><code>&lt;div&gt;
      &lt;asp:Panel ID="Panel1" runat="server" Width="300px" /&gt;
      &lt;asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Code-behind:</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();          
          Label lblU = new Label();          
          TxtBoxU.ID = "TextBoxU" + i.ToString();            
          lblU.ID = "LabelU" + i.ToString();         
          lblU.Text = "Category Name " + (i + 1).ToString() + " : ";
  
          //Add the labels and textboxes to the Panel.
          Panel1.Controls.Add(lblU);
          Panel1.Controls.Add(TxtBoxU);
      }
  }
  </code></pre>