title: Assigning a value to a hidden form field with JQuery in asp.net webforms
body: <p>I have a project I'm working on in webforms and I've run into a hitch trying to assign a value to a hidden form field and then accessing it from the code behind; which is resulting in a null value.  I usually work on MVC applications, so I'm a bit confused.</p>
  
  <p>This is the JQuery:</p>
  
  <pre><code>$('.button-submit').click(function () {
      var foo = 'bar';
      $('#hiddenField').val(foo);
  });
  </code></pre>
  
  <p>This is my form:</p>
  
  <pre><code>&lt;form id="form1" runat="server"&gt;
  
      &lt;input type="hidden" id="hiddenField" value="" /&gt;
  
      &lt;asp:Button ID="ButtonSubmit" runat="server" OnClick="ButtonSubmit_Click" Text="Add New"  class="button-submit" /&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>And this is in the code behind:</p>
  
  <pre><code>protected void ButtonSubmit_Click(object sender, EventArgs e)
  {
      string hiddenFormValue = Request.Form["hiddenField"];
  }
  </code></pre>
  
  <p><code>Request.Form["hiddenField"]</code> is <code>null</code>.  I also tried <code>Request.Params</code> and got a <code>null</code>.  Any ideas on how I can either fix this code or recommended a better way to implement?  I also tried to use an <code>asp:HiddenField</code> control, which was getting the assigned value (tested with <code>alert($('#hiddenField').val()</code>); but still ending up as an empty string in the code behind.</p>