Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Redirection script

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gee - 12 Mar 2008 19:26 GMT
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.
Mark Rae [MVP] - 12 Mar 2008 19:46 GMT
>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
[quoted text clipped - 3 lines]
>
> 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/library/system.web.ui.clientscriptmanager.regis
terstartupscript.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');");

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

bruce barker - 12 Mar 2008 21:56 GMT
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)

> 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
[quoted text clipped - 9 lines]
>
> It is like I need it to do another postback to fire the script.
Gee - 13 Mar 2008 00:52 GMT
Thanks

It doesn't work. I am guessing because it is done server side.

> for this to work, the users will have to make your site trusted, and
> enable
[quoted text clipped - 18 lines]
>>
>> It is like I need it to do another postback to fire the script.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.