in code behind :
string func = "showSuccessMessage(开发者_运维百科"+name+");";
ClientScript.RegisterStartupScript(this.GetType(), "success", func, true);
in a js file :
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
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
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
so the question stands :
how does one send arguments to a javascript function from code-behind
thanks in advance eran.
btw similar question : showing something similar to what iv'e attempted
similar question
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
Correct that with
string func = "showSuccessMessage('"+name+"');";
精彩评论