0

I have a page on my site on which users have to fill out details before they can download a document. The user details section is on the first view in a MultiView control.

After filling out their details I'd like the user to click a button which will show them a file download prompt (I've done this successfully with an ashx handler) then redirect them to the second view page of the MultiView which will say "thank you for downloading" or something like that.

I've tried the usual Response.Redirect("~/DownloadHandler.ashx"); within the button click event handler, but obviously this prevents the page completing the postback and showing the last page of the MultiView.

Is there a way around this, or should I just change my UI to accommodate this?

EDIT: I've concluded that it's better to just provide a hyperlink to the document (on my confirmation page, and change the wording accordingly) as this provides a consistent user experience independent of the browser they're using.

Matthew Dresser
  • 11,273
  • 11
  • 76
  • 120

1 Answers1

1

Go ahead and take them to the second view of the MultiView. Add a javascript method that will download the document, and trigger it from your codebehind.1 E.g.,

In your page:

<script>
function downloadFile(url) {
 window.location = url;
 //you could also try window.open(url, 'Download')
}
</script>

In your code behind:

script = string.Format("downloadFile('{0}');", "DownloadHandler.ashx");
Page.ClientScriptManager.RegisterStartupScript(typeof(Page), "download", script, true);

You could also add a delay (using setTimeout) before the file is downloaded.

More info: Initiating a file download that works well, even in IE?

Community
  • 1
  • 1
ultravelocity
  • 2,099
  • 16
  • 17