title: how to get the value of dynamically populated controls
body: <p>I have a div Conatining a Panel in aspx page</p>
  
  <pre><code>&lt;div id="divNameofParticipants" runat="server"&gt;
      &lt;asp:Panel ID="panelNameofParticipants" runat="server"&gt;
      &lt;/asp:Panel&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I am populating the panel dynamically from codebehind with the following code:</p>
  
  <pre><code>void btnSubmitCountParticipant_Click(object sender, EventArgs e)
      {
          StringBuilder sbparticipantName=new StringBuilder();
  
          try
          {
              int numberofparticipants = Convert.ToInt32(drpNoofparticipants.SelectedValue);
              ViewState["numberofparticipants"] = numberofparticipants;
              Table tableparticipantName = new Table();
              int rowcount = 1;
              int columnCount = numberofparticipants;
              for (int i = 0; i &lt; rowcount; i++)
              {
                  TableRow row = new TableRow();
                  for (int j = 0; j &lt; columnCount; j++)
                  {
                      TableCell cell = new TableCell();
                      TextBox txtNameofParticipant = new TextBox();
                      txtNameofParticipant.ID = "txtNameofParticipant" + Convert.ToString(i);
                      cell.ID = "cell" + Convert.ToString(i);
                      cell.Controls.Add(txtNameofParticipant);
                      row.Cells.Add(cell);
  
  
                  }
                  tableparticipantName.Rows.Add(row);
                  panelNameofParticipants.Controls.Add(tableparticipantName);
  
              }
  
          }
          catch(Exception ex)
          {
  
  
          }
      }
  </code></pre>
  
  <p>Now I want to access the value of these dynamically generated textbox in the codebehind.for which i my code is as under:</p>
  
  <pre><code>public void CreateControls()
      {
  
          try
          {
              //String test1 = test.Value;
              List&lt;string&gt; listParticipantName = new List&lt;string&gt;();
              if (ViewState["numberofparticipants"] != null)
              {
                  int numberofparticipants = Convert.ToInt32(ViewState["numberofparticipants"]);
                  for (int i = 0; i &lt; numberofparticipants; i++)
                  {
                      string findcontrol = "txtNameofParticipant" + i;
                      TextBox txtParticipantName = (TextBox)panelNameofParticipants.FindControl(findcontrol);
                      listParticipantName.Add(txtParticipantName.Text);
  
                  }
              }
          }
          catch (Exception ex)
          {
  
          }
      }
  </code></pre>
  
  <p>but I am not able to get the values in codebehind.</p>
  
  <pre><code> TextBox txtParticipantName = (TextBox)panelNameofParticipants.FindControl(findcontrol);
  </code></pre>
  
  <p><strong>the above code is not able to find the control and its always giving null</strong>.what am i doing wrong.i recreated the controls in page load also since postback is stateless but still no success.</p>
  
  <p>Thanks in Advance</p>