title: Passing arguments to JavaScript function from code-behind
body: <p>I would like to call a javascript function from an aspx control.  For instance, suppose I had:</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head runat="server"&gt;
  &lt;title&gt;Untitled Page&lt;/title&gt;
  &lt;script type="text/javascript"&gt;
      function test(x, y)
      {
  
      }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
          &lt;asp:Button ID="Button1" runat="server" Text="Button"
           onclick="Button1_Click"/&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and in the code behind:</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
      // do stuff (really going to a database to fill x and y)
      int[] x = new int[] { 1, 2, 3, 4, 5 };
      int[] y = new int[] { 1, 2, 3, 4, 5 };
  
      // call javascript function as test(x,y);
  }
  </code></pre>
  
  <p>Is there a way to do it?</p>