Im trying to use an asp:progress so when I click on my asp:button it calls an ashx file which write a CSV response.
So far when I click on the button, the animation shows properly and the download start. However I can't seem to stop the animation when the file start downloading (when I get the response from the ashx file).
Here is the aspx :
<asp:Content ID="Content2" ContentPlaceHolderID="MainPlaceHolder" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<p>Download a CSV file</p>
<asp:Button ID="Button2" runat="server" Text="Download"
CausesValidation="False" onclick="Button2_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID="UpdatePanel1" runat="server">
<ProgressTemplate>
<div id="AlertDiv" style="background:White">
<asp:Image ID="imgLoading" runat="server" ImageUrl="css/smoothness/images/animated-overlay.gif" Width="34px" />Loading...
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</asp:Content>
Here is the Button2_click function :
protected void Button2_Click(object sender, EventArgs e)
{
try
{
Response.Redirect("ProductsHierarchyDownload.ashx");
}
catch (Exception ex)
{
//log
}
}
And here is the ProcessRequest function from the ashx file :
public void ProcessRequest(HttpContext context)
{
string attachment = String.Format("attachment; filename=Hierarchie des produits au {0}.csv", DateTime.Today.ToShortDateString());
context.Response.AddHeader("content-disposition", attachment);
context.Response.ContentType = "text/csv";
context.Response.AddHeader("Pragma", "public");
context.Response.ContentEncoding = Encoding.GetEncoding(1252);
context.Response.Write(DemandeTarifImageBLL.DataTableToCSVString());
}
I've tried to use javascript and the property endRequest, beginRequest and initializeRequest event of the PageRequestManager Class (I found some conde snippet here) but nothing has worked for me so far.
How do I force the animation to stop when the download starts ?