views:

466

answers:

3

I've got a problem on a webforms application where a user selects some criteria from dropdowns on the page and hits a button on the page which calls this method:

protected void btnSearch_Click(object sender, EventArgs e)

They then click on button to download a zip file based on the criteria which calls this method:

protected void btnDownload_Click(object sender, EventArgs e)

In IE, they are prompted with the bar at the top of the browser that tells them "To help protect your security, Internet Explorer blocked this site from downloading files to your computer". When they click on that bar to download the file, it fires the btnSearch_Click event again.

Response.ContentType and Response.AddHeader has been set up correctly.

The problem is, that btnSearch appends criteria so basically it is being appended twice and causing problems.

Is there something I can do to prevent this?

This is a vs2008 web app using c# 3.5 for what it's worth.

Thanks!

A: 

Are you using the Content-Disposition header?

Response.AddHeader("Content-Disposition", "attachment; filename=fileName.zip");

Try changing the content type to match the file type?

Greg Dean
Yes, I am doing the following:Response.ClearContent();Response.ClearHeaders();Response.ContentType = "application/octet-stream";Response.AddHeader("Content-Disposition", "attachment;filename=" + strFileName);Response.AddHeader("Content-Length", new FileInfo(strFileLocation).Length.ToString());
Chris Conway
It works for me with no warning bar. Try changing the content type to match the file type?
Greg Dean
A: 

Save a boolean value into the Session indicating that the criteria have been already appended. When the user selects another value from the dropdowns then set this value to false.

Inside your btn_Download event you then can check the value of the Session variable and avoid setting the criteria twice.

Greco
I can't do that, mostly because the criteria button builds criteria one at a time, so it is perfectly reasonable for that button to be called several times before the user finally hits the download button.
Chris Conway
A: 

When they click the download button, do a Redirect to the ZIP file handler (page?) to download the file. i.e. use the Post-Redirect-Get pattern: http://en.wikipedia.org/wiki/Post/Redirect/Get

Hightechrider