title: Setting value of hiddenfield with Jquery and retrieve value server side
body: <p>My scenario is this. User clicks on button and a modal dialog appears with a checkboxlist. When the user makes their selections and clicks 'ok' in client click event I want to set a hiddenfield with the list of values the user selected. The user continues with rest of form and clicks another button to submit the whole form. From code behind (button Click event) I need to access this list of values that was stuffed into the hiddenfield to save to DB.</p>
  
  <p>ClienclickEvent code</p>
  
  <pre><code> function onOk() {
          var selectedItems = [];
          $("[id*=CategoryCheckboxList] input:checked").each(function () {
              selectedItems.push(this.value);
          });
          //stuff the values in the hidden field for later postback
          $("#hiddenCategoryHash").value = selectedItems; //appears to work, no errors
          $("#debugcat").text(selectedItems); //stuff into a div for testing (works)
          $("#dbg").text = selectedItems;   //attempted to stuff in Textbox. FAIL
          }
  </code></pre>
  
  <p>It should be noted that I have also tried this with an html input control and using request.form to retrieve the values that way, but does not work either. Do I have the right approach here? Should I go about this in a different manner?</p>
  
  <p>Here is the markup</p>
  
  <pre><code> &lt;asp:HiddenField ID="hiddenCategoryHash" runat="server" EnableViewState="true"   /&gt;
  &lt;asp:TextBox ID="dbg" runat="server"&gt;&lt;/asp:TextBox&gt;
  &lt;input type="hidden" name="conf4" value="test" /&gt;
  </code></pre>
  
  <p>Lastly here is the code behind</p>
  
  <pre><code>xfer.IsActive = True
      xfer.IsDiscontinued = False
      Dim hiddenval = Request.Form("hiddenCategoryHash")
      Dim test = hiddenCategoryHash.Value
      Dim debugdiv = Request.Form("debugcat")
      xfer.CategoryIDhash = hiddenval
      dc.Transfers.InsertOnSubmit(xfer)
      dc.SubmitChanges()
  </code></pre>
  
  <p>Thank you for all your suggestions. As it turns out I had to grab the full clientID of the hidden control in my jquery selector, like so:  $("#&lt;%= hiddenCategoryHash.ClientID %>").val(selectedItems);.</p>