简体   繁体   中英

How to run javascript after PDF file Download

I download a FILE to PDF , everything works. I show a loading Image before running the process as it can take several seconds or minutes to collect data from DB to make the file .

<p>
    <asp:LinkButton Height="40" OnClientClick="showLoading();"
        OnClick="btnDownload2_Click" runat="server" CssClass="btn btn-success" ID="LinkButton1"
        Text="Click Here to Download List of Registered Students per course">
        <span style="text-align:center"> Download List&nbsp;&nbsp;&nbsp;</span>
        <img id="Img2" style="display:none" src="../../images/ajax-loader.gif" alt="Loading" />
    </asp:LinkButton>
</p>

The issue is when the file gets downloaded how can i change the Img2 back to original style. If it was not Resonse.Write it would automatically have switched to original style after button event finished.

This is the file download Process ....(end part)...

Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename="+reportName+".pdf");
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
Response.Close();

Any suggestions?

Just add a query string value to indicate success, then on page load check for it and add a class.

So when a file download has finished:

Response.Redirect("yourUrl" + "?Success=true");

Then on your page load:

if (Request.QueryString["Success"] != null)
{
    LinkButton1.CssClass += " file-downloaded";
}

Your button has runat server, btnDownload2_Click it's a method from codebehind and you are making a postback to download .

On the same method at the finish just add:

Page.RegisterStartupScript("change_image", "document.getElementById(""Img2"").src=""../../images/loader-finish.gif"";");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM