1

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?

3 Answers 3

1

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 "

Edit 1

When you call a function and if you have to pass a static values you always use ' or " in javascript.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

Check this work.

  <script>
        ids="1,2";
    function OpenCenterWindow(Ids) {
        alert("herer");
    alert(Ids);
    }

        OpenCenterWindow(ids);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.