title: Changing asp:HiddenField.value with JS on ButtonClick
body: <p>I have four textboxes in my html; one is a serverside asp:textbox and the others are rendered on the client side using dynamic javascript.  The javascript creates the textareas; there may be 6, there may be 90.  In this example there are 3.</p>
  
  <pre><code>&lt;asp:Textbox id="tbxReal" runat="server"/&gt;
  &lt;asp:button id="btnReal" runat="server" Value="go" /&gt;
  &lt;asp:HiddenField ID="hdnID" runat="server" /&gt;
  
  &lt;textarea rows="10" cols="60" id="one"&gt;&lt;/textarea&gt;
  &lt;input onclick="sub('one');" type="button" value="Go_One" /&gt;
  
  &lt;textarea rows="10" cols="60" id="two"&gt;&lt;/textarea&gt;
  &lt;input onclick="sub('two');" type="button" value="Go_Three" /&gt;
  
  &lt;textarea rows="10" cols="60" id="one"&gt;&lt;/textarea&gt;
  &lt;input onclick="sub('three');" type="button" value="Go_Three" /&gt;
  </code></pre>
  
  <p>I want to be able to submit the javascript rendered textbox/buttons through the 1 set of server side controls.</p>
  
  <p>Here is my javascript:</p>
  
  <pre><code>function sub(id)
  {
      hdn = document.getElementById('WhatGetsAppended_hdnID');
      hdn.value = id;
      alert(hdnID.value);
  
      var Real = document.getElementById('WhatGetsAppended_tbxReal');
      var Fake = document.getElementById(id);
      Real.value = Fake.value;
  
      var button = document.getElementById('WhatGetsAppended_btnReal');
      button.click();    
  }
  </code></pre>
  
  <p>Then the C# event handler for the tbxReal:</p>
  
  <pre><code>protected void btnReal_Click(object sender, EventArgs e)
  {
      Response.Write(Convert.ToInt32(hdnID.Value) + "&lt;BR /&gt;");
      Response.Write(tbxReal.Text + "&lt;BR /&gt;");
  }
  </code></pre>
  
  <p>My code works for changing the text within tbxReal, but I can't change the value of hdnId when the postback occurs. How do I fix my code so that I can change the value of the HiddenField in Javascript and have the postback read that new value?</p>
  
  <p>Edit: Acknowledged that I know what the clientIDs of the serverside controls are within the JS.</p>