Redirection script

G

Gee

I have a form which I need to redirect to a file (could be PDF or Word)
which is on the clients local system but I am having touble getting it to
fire the javascript.

In the PageLoad if not a postback I do

string oFileScript = "<script language='javascript'>" +

"window.location='file:///" + fileName + "';</script>";

Page.RegisterStartupScript("OpenFile", openFileScript);

It is like I need it to do another postback to fire the script.
 
M

Mark Rae [MVP]

I have a form which I need to redirect to a file (could be PDF or Word)
which is on the clients local system but I am having touble getting it to
fire the javascript.

In the PageLoad if not a postback I do

string oFileScript = "<script language='javascript'>" +

Firstly, that's deprecated syntax - use <script type="text/javascript">
instead or, better still, use the Boolean overload to have ASP.NET add the
script tags for you automatically:
http://msdn2.microsoft.com/en-us/li...lientscriptmanager.registerstartupscript.aspx
Page.RegisterStartupScript("OpenFile", openFileScript);

Secondly, RegisterStartupScript takes either three or four parameters, not
two...

Thirdly, you're populating a string variable called oFileScript, but you're
not actually using it - oFileScript is not the same as openFileScript...
It is like I need it to do another postback to fire the script.

Also, be aware that RegisterStartupScript method places the JavaScript at
the bottom of the ASP.NET page right before the closing </form> element. If
you want the script to be placed directly after the opening <form> element
so that it executes before the rest of the form element, then you need the
RegisterClientScriptBlock method.

Try placing this in your Page_Load:

ClientScript.RegisterClientScriptBlock(GetType(), "topCode",
"alert('Top');");
ClientScript.RegisterStartupScript(GetType(), "bottomCode",
"alert('Bottom');");
 
B

bruce barker

for this to work, the users will have to make your site trusted, and enable
the file open. so you might as just redirect to the file and not use
javascript.

Response.Redirect("file:///" + fileName);


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top