如何在回发发生时启动加载程序,然后加载程序应在 ASP.NET 后停止?
How to start a loader when a postback happens,then after that loader should be stopped in ASP.NET?
当用户单击“导出”按钮时,我触发加载程序事件以启动加载程序。使用 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";
}
尝试以下客户端解决方案 基于Sys.WebForms.PageRequestManager class:
<!-- 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。
当用户单击“导出”按钮时,我触发加载程序事件以启动加载程序。使用 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";
}
尝试以下客户端解决方案 基于Sys.WebForms.PageRequestManager class:
<!-- 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。