Calling a javascript function from an aspx.cs code behind

Posted by David Hodgson on Stack Overflow See other posts from Stack Overflow or by David Hodgson
Published on 2009-04-25T06:16:46Z Indexed on 2010/06/10 10:12 UTC
Read the original article Hit count: 221

Filed under:
|
|
|

Hi,

I would like to call a javascript function from an aspx control. For instance, suppose I had:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
    function test(x, y)
    {

    }
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button"
         onclick="Button1_Click"/>
    </div>
    </form>
</body>
</html>

and in the code behind:

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);
}

Is there a way to do it?

DUPLICATE:calling-a-javascript-function-at-the-end-of-button-click-code-behind

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET