Sumit Gupta
Sumit Gupta

Reputation: 569

Save dialog box through javascript

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.

Upvotes: 2

Views: 1627

Answers (1)

James Kovacs
James Kovacs

Reputation: 11651

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.

Upvotes: 4

Related Questions