title: Setting a value to a HiddenField in ASP.NET 4.5
body: <p>I'm having some issues setting a value to a HiddenField in ASP.NET 4.5.</p>
  
  <p>From what I've seen I've tried the following without any luck:</p>
  
  <p>In ASPX:</p>
  
  <pre><code>&lt;asp:HiddenField ID="HiddenField" runat="server" value="" /&gt;
  &lt;script type="text/javascript"&gt;
      function SetHiddenField() {
          var vv = "HELLO WORLD";
          document.getElementById('&lt;%=HiddenField.ClientID%&gt;').value = vv;            
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>In code-behind:</p>
  
  <pre><code>ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "SetHiddenField", "SetHiddenField();", true);
  ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('" + HiddenField.ClientID + "');", true);
  </code></pre>
  
  <p>This alerts garbage in the ClientID.</p>
  
  <p>The other solution I've tried is the following.</p>
  
  <p>In .ASPX:</p>
  
  <pre><code>&lt;asp:HiddenField ID="HiddenField" runat="server" value="" /&gt;
  &lt;script type="text/javascript"&gt;
      function SetHiddenField() {
          var vv = "HELLO WORLD";
          document.getElementById('HiddenField').value = vv;            
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>One issue here is that <code>.value</code> does not exist in the IntelliSense, only <code>.ValueOf</code>.</p>
  
  <p>In code-behind:</p>
  
  <pre><code>ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "SetHiddenField", "SetHiddenField();", true);
  ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('" + HiddenField.Value + "');", true);
  </code></pre>
  
  <p>Nothing happens, probably an error in the JavaScript, since no alert is shown.</p>
  
  <p>Can anyone point me to the right direction, please?</p>