传递参数给javascript函数从code-落后,错误 [英] passing arguments to javascript function from code-behind , error
问题描述
在code背后:
string func = "showSuccessMessage("+name+");";
ClientScript.RegisterStartupScript(this.GetType(), "success", func, true);
在一个js文件:
function showSuccessMessage(user)
{
$("#box").dialog({
title:"User Registration",
html: user.toString() + " Successfully Registered",
modal: true,
buttons: {
Ok: function () {
$(this).dialog("close");
var s = "../Pages/main.aspx";
window.location = s;
}
}
});
} // end function
当我尝试通过FUNC字符串不带参数的每一件事情的工作了罚款
when i try to pass the func string with no arguments every thing works out fine
当我尝试参数追加到函数的字符串我从浏览器中得到一个错误
when i try to append the argument into the function string i get an error from the browser
未捕获的ReferenceError:未定义约翰
Uncaught ReferenceError: john is not defined
(约翰是名称的值)
现在我猜测该问题的发生是因为该函数被注册它不能涉及的变量和值区分,因此它是一个非限定型约翰的方式
(john being the value of name) now i'm guessing the problem occurs because the way the function is registered it can't distinguish between a the variable and the value , so it is a non-defined type john
这样的问题存在:
一个人如何从code-后面的参数发送到JavaScript函数
how does one send arguments to a javascript function from code-behind
在此先感谢
伊兰。
thanks in advance eran.
顺便说一句类似的问题:
显示出类似iv'e尝试什么东西
btw similar question : showing something similar to what iv'e attempted
<一个href=\"http://stackoverflow.com/questions/788330/passing-arguments-to-javascript-function-from-$c$c-behind\">similar问题
推荐答案
你正在写的方式,就好像在约翰
传递作为一个变量,而不是一个字符串。这就像调用
The way you are writing it, it's like passing in john
as a variable, not a string. It's like invoking
showSuccessMessage(john); // what you're doing in js
showSuccessMessage('john'); // what you need
纠正以
string func = "showSuccessMessage('"+name+"');";
这篇关于传递参数给javascript函数从code-落后,错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!