title: Get client-side value to server-side ASP.NET
body: <p>I tried to pass a variable from the client side to server side using <code>HiddenField</code> like in <a href="https://stackoverflow.com/questions/11600766/pass-client-side-javascript-value-to-server-side-c-sharp">this</a> example. </p>
  
  <p>What I have tried so far:</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
  
      &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head runat="server"&gt;
          &lt;title&gt;&lt;/title&gt;
          &lt;script type ="text/javascript"&gt; 
           &lt;script type ="text/javascript"&gt; 
                  function passValue() {
                      document.getElementById('&lt;%=HiddenField1.ClientID%&gt;').value = "some stuff";
                  }
                   window.onload = passValue;
  
              &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;    
          &lt;form id="form1" runat="server"&gt;
          &lt;div&gt;    
              &lt;asp:HiddenField ID="HiddenField1" runat="server"/&gt;
  
              &lt;asp:Button ID="Button1" runat="server" Text="Button" OnClientClick ="passValue()"/&gt;
  
          &lt;/div&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>On the server side I have the following code:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
          {
              string a, b;
              if (IsPostBack)
              {
                  Response.Write("The input value is: " + HiddenField1.Value.ToString());
                  a = HiddenField1.Value.ToString();
              }
              else
              {
                  Response.Write("The input value is: " + HiddenField1.Value.ToString());
                  b = HiddenField1.Value.ToString();
              }
          }
  </code></pre>
  
  <p>When my page opens I expect to see on it the message: "The input value is: some stuff". The message appears only if I press the button because only in this case the IsPostBack becomes true.
  What should I do so get the message without pressing the button? Thanks in advance!</p>