title: HOw can I handle Dynamically generated Controls
body: <p>In the following image the table displayed is generated dynamically on click of “Create Table” button.</p>
  
  <p>I have added textboxes, fileupload, Buttons dynamically to the table.</p>
  
  <p>I want to upload files from fileupload control on click of “Upload” button in the Table, but I have no idea how to handle those Dynamically generated Controls.</p>
  
  <p>Code of “Create Table”  button goes like this :</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
      //Button1.Visible = false;
      //Creat the Table and Add it to the Page
      Table table = new Table();
      table.Caption = "Table1";
      table.BackColor = System.Drawing.Color.BurlyWood; 
      Page.Form.Controls.Add(table);
      for (int i = 0; i &lt; 3; i++)
      {
          TableRow row = new TableRow();
          row.BorderStyle = BorderStyle.Ridge;
  
          for (int j = 0; j &lt;= 10; j++)
          {
              TableCell cell = new TableCell();
              cell.BorderWidth = 5;
              cell.BorderStyle = BorderStyle.Ridge;
              cell.BorderColor = System.Drawing.Color.Azure; 
              for (j = 0; j &lt;= 0; j++)
              {
                  Label lbl = new Label();
                  lbl.ID = "lblCCRow" + i + "Col" + j;
                  lbl.Text = "CC NO. " + i + " ";
                  lbl.Width = 100;
                  // Add the control to the TableCell
                  cell.Controls.Add(lbl);
              }
  
              for (j = 1; j &lt;= 1; j++)
              {                        
                  Label lbl = new Label();
                  lbl.ID = "lblRow" + i + "Col" + j;
                  lbl.Width = 100;
                  lbl.Text = Convert.ToString(DateTime.Now.Day) + "/" + Convert.ToString(DateTime.Now.Month) + "/" + Convert.ToString(DateTime.Now.Year);
                  // Add the control to the TableCell
                  cell.Controls.Add(lbl);
              }
  
              for (j = 2; j &lt;= 7; j++)
              {                        
                  TextBox tb = new TextBox();
                  tb.Width = 100;
                  tb.ID = "txtBoxRow" + i + "Col" + j;
                  tb.Text = "";
                  // Add the control to the TableCell
                  cell.Controls.Add(tb);
              }
  
              for (j = 8; j &lt;= 8; j++)
              {
                  FileUpload fileUp = new FileUpload();
                  fileUp.ID = "flupRow" + i + "Col" + j;
                  fileUp.Width = 220;
                  cell.Controls.Add(fileUp);
              }
  
              for (j = 9; j &lt;= 9; j++)
              {                        
                  Button btnUpld = new Button();
                  btnUpld.Width = 100;
                  btnUpld.ID = "btnUpRow" + i + "Col" + j;
                  btnUpld.Text = "Upload";
                  cell.Controls.Add(btnUpld);
              }
  
              for (j = 10; j &lt;= 10; j++)
              {
                  Label lbl = new Label();
                  lbl.ID = "lblRow" + i + "Col" + j;
                  lbl.Text = "[ Status ]";
                  lbl.Width = 100;
                  // Add the control to the TableCell
                  cell.Controls.Add(lbl);
               }
  
               row.Cells.Add(cell);
           }
  
           // Add the TableRow to the Table
           table.Rows.Add(row);
       }
       //table.Rows.Add(row);  
   }    
  </code></pre>