Asp: progress will not end when the file is loaded from the ashx file

I am trying to use asp: progress, so when I click the asp: button, it calls the ashx file that writes the CSV response.

While I press the button, the animation displays correctly and the download starts. However, I cannot stop the animation when the file is uploaded (when I get a 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 tried using javascript and the property endRequest, beginRequest and initializeRequest event of the PageRequestManager class (I found the conde snippet here ) but nothing has worked so far.

How to make animation stop at loading?

+4
3

, , , . :

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());
    context.Response.Flush();
    context.Response.End();
}

Flush End . , , .

script, :

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(EndRequest);

function EndRequest(sender, args) {
            if (postBackElement.id == 'Panel1Trigger') {
                $get('UpdateProgress1').style.display = 'none';
            }
        }

js , .

ProcessRequest Flush() End .

1:

, , , :

asp: UpdateProgress

, .

+1

ashx javascript.

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "downloadFileExport", "javascript:window.location ='" + ResolveUrl(downloadUrl) + "';", true)

.

+1

In my ASP.Net Web Forms application, progress text continued to be displayed even after the process was completed. I was able to fix this in the Dev environment by increasing the timeout in ScriptManager. An example is below.

enter image description here

0
source

Source: https://habr.com/ru/post/1527872/


All Articles