简体   繁体   English

PDF文件下载后如何运行javascript

[英]How to run javascript after PDF file Download

I download a FILE to PDF , everything works. 我将FILE下载为PDF,一切正常。 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 . 在运行该过程之前,我显示了一个加载映像,因为从DB收集数据来制作文件可能需要几秒钟或几分钟。

<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. 问题是下载文件时,如何将Img2更改回原始样式。 If it was not Resonse.Write it would automatically have switched to original style after button event finished. 如果不是Resonse.Write则按钮事件完成后,它将自动切换为原始样式。

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 . 您的按钮具有runat服务器btnDownload2_Click,它是代码隐藏的一种方法,您正在回发下载。

On the same method at the finish just add: 最后使用相同的方法添加:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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