title: Get Value of Dynamically Added HiddenField
body: <p>I have a page where I'm dynamically adding HiddenFields through code behind.  I'm adding each of these HiddenFields (HF) from a list, the code I have to try and get the value of this list later is:</p>
  
  <pre><code>// Get the name of the hidden field using a specific cell in a grid.
  string controlName = "hidden_value_" + grdMyGrid.Rows[i].Cells[1].Text;
  HiddenField field = (HiddenField)this.FindControl(controlName);
  string fieldValue = field.Value;
  </code></pre>
  
  <p>However <code>field</code> gets returned as null.  I've tried <code>this.Page.FindControl</code> but this has the same result.</p>
  
  <p>So what I'm wondering is it because of where the <code>HiddenFields</code> are in the Source?   Here is an example of the positioning, with the HF's being outside of the main HTML.  If this is the case how can I actually get these fields?</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head id="head"&gt;
      &lt;script type="text/javascript"&gt;
          // Random script here, not important
      &lt;/script&gt;
  &lt;body&gt;
  
      // Main body of my code, lots of different controls.  Not connected to
      // the HiddenFields at the very bottom.
  
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;asp:HiddenField id='hidden_value_MyValue1' runat='server' value='1' /&gt;&lt;asp:HiddenField id='hidden_value_MyValue2' runat='server' value='2' /&gt;&lt;asp:HiddenField id='hidden_value_MyValue3' runat='server' value='3' /&gt;
  </code></pre>
  
  <p><strong>EDIT - UPDATED CODE</strong>
  This is how I am now adding my hidden values to the page</p>
  
  <pre><code>                foreach (var product in products)
                  {
                      string hiddenValueControl = "&lt;input type='hidden' id='hidden_value_" + product.Description +
                                                  "' runat='server' value='" + product.AlphaKey + "' /&gt;";
                      productLiteral.Text = productLiteral.Text + hiddenValueControl;
                  }
  </code></pre>
  
  <p>How can I then get one of these values?  I've tried this but it ends up returning null</p>
  
  <pre><code>         string tempProductId =
                       Request.Form["hidden_value_" + "MyProductName"];
  </code></pre>