Reputation: 14871
I am dynamically generating a file from server based on user input. I need to provide a download button which, upon clicking, downloads a file to the user's file system.
Also, the user might click the same button twice, upon which the file should download again.
The dynamic generation of file rules out the HttpResponse.TransmitFile() option, which suports mutliple download.
Almost every other option I have come across needs Response.End() to be invoked, which prevents a second download.
How do I satisfy the 'multiple download" requirement?
Read up on Virtual Path providers, which might enable me to use TransmitFile(), but that looks like an overkill for such a simple requirement.
Upvotes: 1
Views: 519
Reputation: 14871
Got the answer from here:
Basically it uses a client side script to reload the page after a download:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
var isReload = false;
function DownloadFiles()
{
if(isReload == true)
{
isReload = false;
window.location.reload();
}
else
{
isReload = true;
}
window.setTimeout("DownloadFiles()", 2000);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label runat="server" ID="lblMsg"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Download" OnClientClick="DownloadFiles();" OnClick="Button1_Click"/>
</div>
</form>
</body>
</html>
Upvotes: 0
Reputation: 25061
You could try either of the following:
Upvotes: 1