Here is my current scenario:
The user clicks on a LinkButton, triggering a PostBack on the page. However, I also need to initiate a file download for the user simultaneously.
To achieve this, I added the following code to the LinkButton:
lnkPrint.Attributes.Add("onclick", "window.open('Download.ashx?type=x')");
The Download.ashx Http Handler creates the file with Content-Type: application/pdf. When I click on the LinkButton, it performs a PostBack and downloads the file while displaying a popup. However, I am unable to automatically close this popup.
I have attempted different methods:
- Using settimeout('self.close()',1000) after the download.
- Utilizing RegisterStartupScript on the LinkButton.Command to initiate the download after the postback, however, IE6 displays a warning that may confuse users.
Unfortunately, none of these approaches seem to work effectively.
Therefore, my question is: Is there a way to instantly close the popup, or is there a method to trigger both the file download and the postback at the same time?
PS: I considered using the Your download will begin shortly technique, but I am concerned about encountering similar issues as with RegisterStartupScript...