【问题标题】:How to start a loader when a postback happens,then after that loader should be stopped in ASP.NET?如何在回发发生时启动加载程序,然后在 ASP.NET 中停止加载程序?
【发布时间】:2017-12-29 06:21:36
【问题描述】:

当我触发加载程序事件以启动加载程序时,当用户单击导出按钮时。哪种方法在客户端使用 jquery 完成。回发发生在我将使用 itextsharp 从 HTML 字符串生成大量 PDF 文档的地方。 毕竟,在客户端浏览器中生成了所有压缩和下载的文件。

我执行以下操作:

 Response.AddHeader("Content-Disposition", "attachment; filename=output.zip");
    Response.TransmitFile(zipPath); 

因为下载后无法停止该加载程序。

服务器端代码背后:

protected void Button1_Click(object sender, EventArgs e)
{
    string test = GetImportDetailsPDF("ImportFile(2)_2017.12.19-12.30.24.xlsx");
    //Generated all pdf files zipped and downloaded here
    string startPath = Server.MapPath("/ImportPdf/");
    string zipPath = Server.MapPath("/ImportZip/result.zip");

    ZipFile.CreateFromDirectory(startPath, zipPath);

    System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
    response.ClearContent();
    response.Clear();
    Response.ContentType = "image/jpeg";
    Response.AddHeader("Content-Disposition", "attachment; filename=output.zip");
    Response.TransmitFile(zipPath);

    HttpContext.Current.Response.Flush(); // Sends all currently buffered output to the client.
    HttpContext.Current.Response.SuppressContent = true;  // Gets or sets a value indicating whether to send HTTP content to the client.
    HttpContext.Current.ApplicationInstance.CompleteRequest(); // Causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event.
    HttpContext.Current.Response.End();
}

public string GetImportDetailsPDF(string FileName)
{

    return "Successfully Imported";
}

【问题讨论】:

  • 你用的是什么拦截工具……它是如何启动的……jQuery blockui等

标签: c#-4.0 asp.net-4.0


【解决方案1】:

尝试以下基于Sys.WebForms.PageRequestManager 类的客户端解决方案

<!-- language: html -->
    <script type="text/javascript">
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_initializeRequest(prm_InitializeRequest);
        prm.add_endRequest(prm_EndRequest);
        function prm_InitializeRequest(sender, args) {
            //show screen blocker
        }
        function prm_EndRequest(sender, args) {
            //hide screen blocker after a file is generated
            //DoClick to download a prepared file
        }
    </script>

使用 UpdatePanel,您可以获得一个非常流畅的解决方案:在文件下载开始之前,您的最终用户不会看到任何回发属性。

您可以找到此方法的详细说明并查看此解决方案的实际操作here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-24
    • 1970-01-01
    相关资源
    最近更新 更多