Javascript breaks after client downloads file to disk

  • Thread starter Thread starter Jeff Cooper
  • Start date Start date
J

Jeff Cooper

Hey there folks,

I have a link on a page which I would like to point to string that's
downloaded as a file -- a *.tab file to be exact. The link points to a file
(download.aspx) which contains no html but uses response.write to send the
data to the client who then downloads it. Problem is, unless I get the
target attribute of the link to _blank, then any javascript I have sitting
on the page gives me an "access is denied" error, but only AFTER a file is
downloaded. I can't just point the link to an existing file since the
contents to be downloaded are generated dynamically.

Below if the code from the load event of download.aspx:

'no html on this page, just that top yellow <@ page ...> line.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim S As String
'
' Bunch of code here to build string S
'
Response.Clear()
Response.ContentType = "text/tab-separated-values"
Response.AppendHeader("Content-Disposition", "attachment;filename=" &
"myfile.tab")
Response.Write(S)
Response.Close()
End Sub

As I said, if I use the tag <A HREF="download.aspx"> then the file
downloads. But, any subsequent javascript I try to execute on the same
page, gives me Access is Denied (I have a drop down list which calls a
function on the onChange event).

If I use the tag <A HREF="download.aspx" target="_blank"> then the file
downloads and I'm ok, except for a new window that's now opened.

I tried doing it all using javascript and a child window:

function doDownload() {
var dlwin
dlwin =
window.open("download.aspx","dlwin","width=10,height=10,dependent=yes,menuba
r=no,toolbar=no,scrollbars=no,resizable=no");
dlwin.close();
}

and changed the link to <A HREF="JavaScript: doDownload()">, but the
dlwin.close() command does not execute for some reason. No error is
reported.

Any advice? Any tips? Any Advil?

Thanks,

Jeff
 
ok, it's not javascript that's breaking, looks like for some reason
selecting an option from a drop down list after downloading a file raises
an "access is denied" error on the client (otgher javascript code seems to
work ok). Still stumped.

I see all sorts of examples of downloading files on the web. Has no one else
had this problem?

Any help greatly appreciated.

Thanks,

Jeff
 
Back
Top