title: Setting hidden input value in Javascript, then accessing it in codebehind
body: <p>I have been trying to set the value of a hidden input by using Javascript and then access the value from within my C# codebehind. When I run the code that is copied below, the value that is assigned to assignedIDs is "", which I assume is the default value for a hidden input. If I manually set the value in the html tag, then assignedIDs is set to that value.</p>
  
  <p>This behavior suggests to me that the value of the input is being reset (re-rendered?) between the onClientClick and onClick events firing.</p>
  
  <p>I would appreciate any help with the matter. I have spent hours trying to solve what seems like a very simple problem.</p>
  
  <p>html/javascript:</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
  &lt;head runat="server"&gt;
  &lt;title&gt;Admin Page - Manage Tasks&lt;/title&gt;
      &lt;script language="javascript" type="text/javascript"&gt;
          function PopulateAssignedIDHiddenInput() {
              var source = document.getElementById('assignedLinguistListBox');
              var s = "";
              var count = source.length;
              for (var i = count - 1; i &gt;= 0; i--) {
                  var item = source.options[i];
                  if (s == "") { s = source.options[i].value; }
                  else { s = s.concat(",",source.options[i].value); }
              }
              document.getElementById('assignedIDHiddenInput').Value = s;
              // I have confirmed that, at this point, the value of
              // the hidden input is set properly
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
          &lt;asp:Panel id="EditMode" runat="server"&gt;
              &lt;table style="border: none;"&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
                          &lt;asp:Label ID="availableLinguistLabel" runat="server" Text="Available"&gt;&lt;/asp:Label&gt;&lt;br /&gt;
                          &lt;asp:ListBox ID="availableLinguistListBox" runat="server" Rows="10" SelectionMode="Multiple"&gt;&lt;/asp:ListBox&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="button" name="right" value="&amp;gt;&amp;gt;"
                              onclick="Javascript:MoveItem('availableLinguistListBox', 'assignedLinguistListBox');" /&gt;&lt;br /&gt;&lt;br /&gt;
                          &lt;input type="button" name="left" value="&amp;lt;&amp;lt;"
                              onclick="Javascript:MoveItem('assignedLinguistListBox', 'availableLinguistListBox');" /&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;asp:Label ID="assignedLinguistLabel" runat="server" Text="Assigned To"&gt;&lt;/asp:Label&gt;&lt;br /&gt;
                          &lt;asp:ListBox ID="assignedLinguistListBox" runat="server" Rows="10" SelectionMode="Multiple"&gt;&lt;/asp:ListBox&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
              //-snip-
              &lt;asp:Button ID="save_task_changes_button" runat="server" ToolTip="Click to save changes to task"
                  Text="Save Changes" OnClick="save_task_changes_button_click" OnClientClick="Javascript:PopulateAssignedIDHiddenInput()" /&gt;
          &lt;/asp:Panel&gt;
  
          &lt;!-- Hidden Inputs --&gt;
          &lt;!-- Note that I have also tried setting runat="server" with no change --&gt;
          &lt;input id="assignedIDHiddenInput" name="assignedIDHiddenInput" type="hidden" /&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>c#</p>
  
  <pre><code>protected void save_task_changes_button_click(object sender, EventArgs e)
  {
      string assignedIDs = Request.Form["assignedIDHiddenInput"];
      // Here, assignedIDs == ""; also, Request.Params["assignedIDHiddenInput"] == ""
      // -snip-
  }
  </code></pre>