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.

Re: Redirection script by Mark

Mark
Wed Mar 12 13:46:57 CDT 2008

"Gee" <somewhere@somone.com> wrote in message
news:uCJMR6GhIHA.4692@TK2MSFTNGP05.phx.gbl...

>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/library/system.web.ui.clientscriptmanager.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');");


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


RE: Redirection script by brucebarker

brucebarker
Wed Mar 12 15:56:01 CDT 2008

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)


"Gee" wrote:

> 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.
>
>
>
>

Re: Redirection script by Gee

Gee
Wed Mar 12 18:52:40 CDT 2008

Thanks

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



"bruce barker" <brucebarker@discussions.microsoft.com> wrote in message
news:4866FD63-741C-4028-B794-B084A771F830@microsoft.com...
> 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)
>
>
> "Gee" wrote:
>
>> 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.
>>
>>
>>
>>