title: Accessing and checking values of dynamic controls ASP.NET
body: <p>I have a scenario. following is the code:</p>
  
  <p>Home.aspx.cs</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
      try
          {
              if (!String.IsNullOrEmpty(txtbox_query.Text.Trim()))
                  {
                      if (isTrue)
                          {
                              // To do statements
                          }
                          else
                          {
                              List&lt;RequestAndResponse.Parameter&gt; parameters = request.getParameter(txtbox_query.Text.Trim(), sourcePath, parameterValue);
                              Session["Data"] = parameters;
                              Response.Redirect("Result.aspx",false);
                          }
  
                      }
  
      }
          catch (Exception error)
          {
                  Response.Write(error.Message);
          }
  }
  </code></pre>
  
  <p>Result.aspx.cs  </p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      parameters = (List&lt;RequestAndResponse.Parameter&gt;)Session["Data"];
          ContentPlaceHolder content = (ContentPlaceHolder)this.Form.FindControl("MainContent");
          for (int j = 1; j &lt;= _arrViewState; j++)
          {
              string _id = j.ToString();
                  TextBox txtfname = new TextBox();
                  txtfname.ID = "TextBox_" + _id + "_";
                  txtfname.Width = 160;
                  txtfname.Text = parameters[(j - 1)].Value.ToUpper();
                  txtfname.Attributes.Add("style", "color:#015D84;font-weight:bold;font-size:12px;padding:10px;");
                  txtfname.EnableViewState = true;
                  content.Controls.Add(txtfname);
                  content.Controls.Add(new LiteralControl("&lt;br/&gt;"));
          }
          Button btnSubmit = new Button();
          btnSubmit.ID = "btnSubmit";
          btnSubmit.Text = "Submit";
          btnSubmit.Click += new System.EventHandler(btnSubmit_click);
          btnSubmit.Enabled = false;
          content.Controls.Add(btnSubmit);
  }
  
  protected void btnSubmit_click(object sender, EventArgs e)
  {
      // How to find the dynamically created textbox
  }
  </code></pre>
  
  <p>Now How to find the dynamically created controls
  I know the basic like:</p>
  
  <pre><code>Form.FindControl("TextBox ID");
  </code></pre>
  
  <p>But here i dont know the textbox id and also i even dont know how many textbox will be their as it totally depends on user input i.e. from 2 TO N textboxes
  What i want is on <code>bttn_Click</code> i will fetch the text from all the textboxes
  How will i achieve this.
  Also i want to check if all Textbox is empty or not on <code>bttn_Click</code></p>