title: How to access dynamically created server controls in asp.net
body: <p>I created a web page and I used to add server side controls to table dynamically. </p>
  
  <p>I assigned them individually the id's.. 
  But I am unable to access these dynamically created server controls.</p>
  
  <p>C# code:</p>
  
  <pre><code> protected void Page_Load(object sender, EventArgs e)
      {
          if (IsPostBack)
          {
              int num_row = (int)Session["No_of_Rows"];
              for (int i = 2; i &lt; num_row; i++)
              {
                  TableRow row = new TableRow();
                  TableCell cell1 = new TableCell();
                  TableCell cell2 = new TableCell();
                  TextBox tb = new TextBox();
                  CheckBox cb = new CheckBox();
  
                  row.ID = "rw" + i;
  
                  cell1.ID = "c" + i + "1";
                  cell2.ID = "c" + i + "2";
  
                  tb.ID = "txt" + i;
                  tb.EnableViewState = true;
                  cb.ID = "chk" + i;
  
                  cell1.Controls.Add(cb);
                  cell2.Controls.Add(tb);
  
                  row.Cells.Add(cell1);
                  row.Cells.Add(cell2);
  
                  tbl.Rows.Add(row);
              }
          }
          else
          {
              Session["No_of_Rows"] = 2;
          }
  
  
  
  
      }
      protected void addRow(object sender, EventArgs e)
      {
  
          int num_row = (int)Session["No_of_Rows"] + 1;
          TableRow row = new TableRow();
          TableCell cell1 = new TableCell();
          TableCell cell2 = new TableCell();
          TextBox tb = new TextBox();
          CheckBox cb = new CheckBox();
  
          row.ID = "rw" + num_row;
  
          cell1.ID = "c" + num_row + "1";
          cell2.ID = "c" + num_row + "2";
  
          tb.ID = "txt" + num_row;
          //tb.EnableViewState = true;
          cb.ID = "chk" + num_row;
  
          cell1.Controls.Add(cb);
          cell2.Controls.Add(tb);
  
          row.Cells.Add(cell1);
          row.Cells.Add(cell2);
  
          tbl.Rows.Add(row);
          Session["No_of_Rows"] = tbl.Rows.Count;
  
  
  
      }
  
      protected void btnSubmit_Click(object sender, EventArgs e)
      {
          TextBox tb = new TextBox();
  
          int num_row = Convert.ToInt16(tbl.Rows.Count);
          for (int i = 1; i &lt; num_row; i++)
          {
              string tstr = "txt" + i;
              tb = (TextBox)this.FindControl(tstr);
  
          }
          Label1.Text = tb.Text;
      }
  </code></pre>
  
  <hr>
  
  <p>asp code:</p>
  
  <pre><code>    &lt;form id="form1" runat="server"&gt;
  &lt;div&gt;
      &lt;asp:Label ID="Label1" runat="server" Text="textbox value is"&gt;&lt;/asp:Label&gt;
      &lt;asp:Table ID="tbl" runat="server"&gt;
          &lt;asp:TableRow ID="rw0"&gt;
              &lt;asp:TableCell ID="c01" Width="100px"&gt;
                  &lt;asp:CheckBox runat="server" ID="chk0" /&gt;
              &lt;/asp:TableCell&gt;
              &lt;asp:TableCell ID="c02" Width="100px"&gt;
                  &lt;asp:TextBox runat="server" ID="txt0" /&gt;
              &lt;/asp:TableCell&gt;&lt;/asp:TableRow&gt;
          &lt;asp:TableRow ID="rw1"&gt;
              &lt;asp:TableCell ID="c11" Width="100px"&gt;
                  &lt;asp:CheckBox ID="chk1" runat="server" /&gt;
              &lt;/asp:TableCell&gt;
              &lt;asp:TableCell ID="c12" Width="100px"&gt;
                  &lt;asp:TextBox runat="server" ID="txt1" /&gt;
              &lt;/asp:TableCell&gt;&lt;/asp:TableRow&gt;
      &lt;/asp:Table&gt;
      &lt;asp:Button ID="btn1" runat="server" Text="Add Row" OnClick="addRow" /&gt;
  &lt;/div&gt;
  &lt;asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Please assist me in this.</strong></p>