title: Run JavaScript from C# ASP.NET
body: <p>I'm trying to run a javascript function from the code behind in C#. I looked at many resourses on internet but so far no luck. This does not even work with a very simple sample code that I have:</p>
  
  <p>Code behind:</p>
  
  <pre><code>  protected void Button2_Click(object sender, EventArgs e)
    {
         ScriptManager.RegisterStartupScript(this,GetType(),"a","a();", true);
    }
  </code></pre>
  
  <p>In my aspx file:</p>
  
  <pre><code> &lt;script type="text/javascript"&gt;
           function a()
           {
               var i = 0;
  
           }
    &lt;/script&gt;
  </code></pre>
  
  <p>When I run this I get :</p>
  
  <blockquote>
    <p>0x800a1391 - JavaScript runtime error: 'a' is undefined</p>
  </blockquote>
  
  <p>Note : </p>
  
  <p>Also tried :</p>
  
  <ul>
  <li>ScriptManager.RegisterStartupScript(this,GetType(),"a","a()", true);</li>
  <li>ScriptManager.RegisterStartupScript(this,GetType(),"a","a", true);</li>
  </ul>
  
  <p>Still getting the same error.</p>
  
  <p><strong>Note for the future reader: The trick is to use an ASP update panel. I did not found a single source to point to this very important fact.</strong></p>