gpt4 book ai didi

c# - 从代码隐藏向 JavaScript 函数传递参数

转载 作者:可可西里 更新时间:2023-11-01 02:14:35 26 4
gpt4 key购买 nike

我想从 aspx 控件调用 javascript 函数。例如,假设我有:

<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>

在后面的代码中:

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

有办法吗?

最佳答案

您可以使用 Page.ClientScript.RegisterStartupScript方法。

关于c# - 从代码隐藏向 JavaScript 函数传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/788330/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com