views:

113

answers:

2

I've been trying to fix this for two hours straight and I can't figure it out.

onclick = "location='exceltest.asp?vanjaar=<%=vanjaar%>&vanmaand=<%=vanmaand%>&vandag=<%=vandag%>&totjaar=<%=totjaar%>&totmaand=<%=totmaand%>&totdag=<%=totdag%>'"

That line of code is in an < input type="button" /> attribute. The button links to a page where an Excel download should be triggered. The values in the URL are from- and to-date-parts. (year, month, day)

this:

onclick = "location='exceltest.asp?fromdate=<%=fromdate%>&todate=<%=todate%>'" />

does not work, because somehow IE7 reads the date (eg. 2008/1/1) wrong. Something to do with the slashes I think.

But when I try to click the button in IE and thus download the generated file, Internet explorer tries do download the file

exceltest.asp?vanjaar=2008vanmaand=1vandag=1totjaar=2008totmaand=2totdag=1

instead of the excel file I want.
FF offers to download the excelfile, but gives (in that excelfile) an overview of an htmlpage with an errormessage telling me my query is wrong (Item cannot be found in the collection corresponding to the requested name or ordinal.) But that CAN'T be, I'm using that exact same query elsewhere, using the same (but restarted) connection.

This is the bit of code I use to instantiate the download of the file:

Response.Buffer = TRUE  
Response.ContentType = "application/vnd.ms-excel"  
Response.AddHeader "content-disposition", "attachment; filename=overicht.xls"

There might actually being to things going on here, but I am most insterested in why IE wants to download the asp page and FF offers the right download.

+4  A: 

The & inside onclick="" should be html-encoded to &amp;

If fromdate contains slashes you're probably safest to url-encode that as well (though you seem to contradict that with your example URL).

Greg
Skunk
A: 

Something that might help: Server.URLEncode

fromdate=<%=Server.URLEncode(fromdate)%>

But, your Excel file error -- Item cannot be found in the collection corresponding to the requested name or ordinal. -- is from Recordset.Fields(). You're trying to grab a field that isn't available -- either a column name that isn't in your query or an index that's beyond your column count.

Jonathan Lonowski
Yes... you're right. The query was wrong after all. My bad... :( I think I will use the URLencode though the matter is solved, it sure would make the URL smaller. Thanks!
Skunk