title: C# asp.net WebForm add JS and run it from code behind
body: <p>I have this <code>WebForm</code> <code>Html</code>:</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetLink.aspx.cs" Inherits="GetLink" %&gt;
  &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;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
      &lt;input type="hidden" runat="server" id="hdnVal" value="55"/&gt;
  
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And i want to add to this code a <code>JavaScript</code> function and run it with this code:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
          if (!ClientScript.IsStartupScriptRegistered("key1"))
          {
              ClientScript.RegisterStartupScript(GetType(), "key1", @"&lt;script type=""text/javascript""&gt;function callMyJSFunction() { document.getElementById(""hdnVal"").value='5'; }&lt;/script&gt;");
          }
  
          ClientScript.RegisterStartupScript(this.GetType(), "key1", "&lt;script&gt;callMyJSFunction();&lt;/script&gt;");
  
          string resutOfExecuteJavaScript = hdnVal.Value;
      }
  </code></pre>
  
  <p>When i run it the value of <code>hdnVal</code> keep the <code>55</code> value and not change. Any  idea what is the problem?</p>