Our client want to be able to run some javascript tracking code when users click on a link to download a PDF. My solution is to pass the name of the file, as a querystring, to a page that then prompts the user to download the file. Is there anyway to get the javascript to run before the .net code?
This is what I'm using on the file download page:
public partial class FileTracking : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string pdf = Request["pdf"] ?? string.Empty;
if (string.IsNullOrEmpty(pdf)) return;
Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" + pdf);
Response.ContentType = "application/octet-stream";
Response.WriteFile(pdf);
Response.Flush();
Response.End();
}
}