running ASP code from an onclick event
Posted on 2004-10-11
I'm embarrased I don't know the answer to this but...
I'm retrieving data from a SQL table and displaying it as a table in the browser. Now I want to give the user the option to download the table as an Excel file.
The code for the download is:
Response.AddHeader "Content-Disposition", "attachment;filename=invoice.xls"
Response.ContentType = "application/vnd.ms-excel"
which works OK but how do I call this from a button?
I assume something like:
<INPUT type="button" value="Download this file" onclick="downloadit()">
Do I put the ASP code inside a function downloadit?
Do I create a variable with a value and then run the response commands with an IF...Then?
What's the best way to do this? Please be explicit, I'm sort of slow today...