2

I am using javascript to open save dialog box

the java script is

function openDialog(path) {

 document.execCommand("SaveAs",true,path);

}

In my project, i am creating linkButtons dynamically and attaching this function with linkButton's OnClient Click event at run time.

            LinkButton linkButton = new LinkButton();
            linkButton.OnClientClick = "openDialog("+file.ToString()+")";

where "file" contains the path of the file which has to be saved.

But i am getting a javascript error as

"Expected ")" "

can anyone help me in what i am doing wrong in this.

I have N number of dynamically created linkButtons and i am associating each linkButton with different file.

1 Answer 1

4

You are not quoting your string so it renders as:

openDialog(someFileName.ext);

which is not valid JavaScript. Change your C# code to read:

linkButton.OnClientClick = "openDialog('"+file.ToString()+"')";

This will render to the browser as:

openDialog('someFileName.ext');

which is valid JavaScript.

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

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.