从C-背后$ C $将参数传递给JavaScript函数 [英] Passing arguments to JavaScript function from code-behind

查看:196
本文介绍了从C-背后$ C $将参数传递给JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个aspx控制调用javascript函数。举例来说,假设我有:

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>

和背后的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);
}

有没有办法做到这一点?

Is there a way to do it?

推荐答案

您可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx">Page.ClientScript.RegisterStartupScript方法。

这篇关于从C-背后$ C $将参数传递给JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆