I have an ASP.NET/C# page. It basically has a textbox to accept user input. The data is processed on the server and a file is generated and saved.
Initially I transmitted the file to the client using Response.TransmitFile()
. However, this process disables the javascript on the page when the file is downloaded.
Therefore, I have designed a .ashx handler to help download the file.
Now, there are two buttons on the page. The user clicks on one to process and create the file. Once the page postbacks, the other button is enabled and should be clicked to download the file (invoke the handler).
What I want to know is how I can wire up the button to call the handler?
Note: I need to send a parameter to the handler as a query string. This parameter is available ONLY in the code behind.
If you specifically want a button, for the request, you could take this approach:
ASPX:
<asp:Button ID="btnDownloadFile" runat="server" OnClick="btnDownloadFile_Click" />
Code-Behind:
protected void btnDownloadFile_Click(object sender, EventArgs e)
{
Response.Redirect(string.Format("/File.ashx?Id={0}", MyParameter);
}