title: ASP.NET Button Control to Trigger Client-side Code which, In Turn, Triggers Server-side Code
body: <p>I've seen a lot of related questions, but don't seem to be able to figure out what to do here.</p>
  
  <p>I have an asp hidden field control defined as </p>
  
  <pre><code>&lt;asp:HiddenField ID="hField" runat="server"&gt;&lt;/asp:HiddenField&gt;
  </code></pre>
  
  <p>and a button control defined as:</p>
  
  <pre><code>&lt;asp:Button ID="btn1" runat="server" usesubmitbehavior="false" onClientClick="return jsFunc()"/&gt;
  </code></pre>
  
  <p>The JavaScript function looks something like this:</p>
  
  <pre><code>function jsFunc() {
      document.getElementById( "hField" ).Value = "someString";
      __doPostBack( "btn1", "" );
   }
  </code></pre>
  
  <p>Finally, in my code behind, I have the following function:</p>
  
  <pre><code>Protected Sub btn1_Click( ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.Click
      ' // access hidden field hField 
  End Sub
  </code></pre>
  
  <p>but the problem is that the value I assigned to the hidden value in the javascript is not persisting the postback.</p>
  
  <p>What do I need to understand or what do I need to do so that the updated hidden field value persists?</p>