编程语言
首页 > 编程语言> > c# – 从后面的代码将变量传递给javascript函数

c# – 从后面的代码将变量传递给javascript函数

作者:互联网

我想从后面的代码将字符串值传递给javascript函数.因为这是我得到一个未被捕获的参考错误的时刻,解释该值未定义.

var variable= txtVariable.Value;
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Registering", "RegisterTheUser("+variable+");", true);

建议也许是正确的语法

这是功能

function RegisterTheUser(val) {
    alert(val);
}

问候

解决方法:

你发布的内容看起来很好.我没有任何问题地使用了以下内容:

ScriptManager.RegisterStartupScript(this, typeof(string), "Registering", String.Format("RegisterTheUser('{0}');", myVariable), true);

你能尝试使用我发布的例子吗?

标签:javascript,c-2,code-behind
来源: https://codeday.me/bug/20190728/1565694.html