title: Get value of dynamically created textbox
body: <p>I'm in a bit of a pickle at the moment, I've created a bit of code that creates 4 textboxes and adds them to a table layout at run time (code below) but I'm struggling with getting text from it, I tried getting the value from it as you would <code>string s = TxtBox1.Text.ToString();</code> but it just gets a null reference, then I tried <code>txt.Text.ToString();</code>and this just gets the text from the last text box that was created.</p>
  
  <pre><code>   private void button2_Click(object sender, EventArgs e)
      {
          int counter;
          for (counter = 1; counter &lt;= 4; counter++)
          {
              // Output counter every fifth iteration
              if (counter % 1 == 0)
              {
                  AddNewTextBox();
              }
          }
      }
  
      public void AddNewTextBox()
      {
          txt = new TextBox();
          tableLayoutPanel1.Controls.Add(txt);
          txt.Name = "TxtBox" + this.cLeft.ToString();
          txt.Text = "TextBox " + this.cLeft.ToString();
          cLeft = cLeft + 1;
      }
  </code></pre>
  
  <p>I've looked all over for the answers to this and as of yet found nothing if anybody has any ideas I would be grateful.</p>
  
  <p>Thanks</p>