Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing a HTML Side JavaScript Function

Status
Not open for further replies.

apc2003

Programmer
Aug 29, 2003
54
0
0
GB
I have a function in the HTML side of my .aspx page with the following code:

Code:
<script type="text/javascript">
<!--
function downloadNow(file,extUrl)
{
var browser = (window.navigator.userAgent.indexOf("SV1") != -1);
if (browser && extUrl==0) 
{
window.open(file, 'DownloadFile', 'width=1,height=1');
window.focus();
}
//-->
</script>

From the C# side I need to execute this method, but when I put a call in for this method using:

Code:
Response.Write(@"<script>downloadnow('"+filePath+@"','0');</script>");

where filePath is my path of the file I want to download...
I keep getting a Javascript Error: "Object Expected"
and the code fails.

Can anyone suggest want is going wrong as I think this should work as the Javascript code runs fine in a standard html page. The problem seems to be when I call the JavaScript method from the C# side.

Regards in advance...
 
the problem occures because the call to the javascript function is made before the function is actually outputed to the page.

to overcome this use
Code:
Literal li = new Literal(@"<script>downloadnow('"+filePath+@"','0');</script>");
Page.Controls.Add(li);

instead of Response.Write(...)

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Thanks for the code but it returns the following error,

Error: No overload for method 'Literal' takes '1' arguments

Please advise as to how to make it work as I am unfamiliar with Literals.

Regards...
 
use LiteralControl instead of Literal (sorry, my bad)

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top