Reputation: 155
Code Like
In .cs page
string test = "1,2";
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "OpenCenterWindow(" + test + ");", true);
JavaScript funcation
function OpenCenterWindow(Ids) {
alert(Ids);
}
In above I am getting alert box = 1
I have try with Encrypt and Decrypt But I am getting error like Uncaught SyntaxError: Unexpected token ) OpenCenterWindow(fBqJaxPUucc=);
But I want to 1,2 any solution?
Upvotes: 1
Views: 1844
Reputation: 17614
Use like below
string test = "1,2";
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script",
"OpenCenterWindow('" + test + "');", true);
You need to pass the values in single quotes'
or double quotest "
When you call a function and if you have to pass a static values you always use '
or "
in javascript.
Upvotes: 1
Reputation: 1264
Check this work.
<script>
ids="1,2";
function OpenCenterWindow(Ids) {
alert("herer");
alert(Ids);
}
OpenCenterWindow(ids);
Upvotes: 0
Reputation: 3268
You can do like this:
string test = "[1,2]";
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "OpenCenterWindow(" + test + ");", true);
So you wil get an integer array in client side:
function OpenCenterWindow(myArray) {
alert(Ids);
}
Upvotes: 1