Monday, March 26, 2012

Why parameter are not passed?

I have a button that once clicked, it opens a new window using Javascript inside of C#.

btnLogin.Attributes.Add("onClick","JavaScript: ftpBrowser(" + strFTPaddress +")");

And here's the Javascript code:

function ftpBrowser(ftpAddress)
{
alert("URL: " + ftpAddress);
var winPop = window.open(ftpAddress, "myWindow");
}

The alert would show an "undefined" as the value of the variable. Any idea how to fix this? Thanks a bunch!

Can you try:

btnLogin.Attributes.Add("onClick","JavaScript: ftpBrowser('" + strFTPaddress +"')"); // Pay attestion: I added single quote in.
 

Hi,

Fix your code as below.

btnLogin.Attributes.Add("onClick","JavaScript: ftpBrowser('" + strFTPaddress +"')");

Never mind I got it working. It needs another single quote for the variable.


Thanks for all the help.

0 comments:

Post a Comment