从asp.net后面的代码调用jquery函数是行不通的

我有一个button点击事件

protected void btndwnReport_Click(object sender, EventArgs e) { try { save("Report1"); } catch (Exception ex) { Log.Errlog("Error Occured in btndwnReport_Clickof UI_Report Page : " + ex.Message.ToString()); } finally { Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "HideLoading", "HideLoading2();", true);//this function is not triggering } } 

使用这个我想使用reportviewer下载一个excel文件。 点击这个button,我显示一个加载图标(通过调用ShowLoading2()),它被定义为一个jQuery的function。

 function ShowLoading2() { try { if (parent.document.getElementById('dvProgress')) $("#dvProgress", parent.document).hide(); } catch (e) { } $("#dvProgress").show(); } function HideLoading2() { try { if (parent.document.getElementById('dvProgress')) $("#dvProgress", parent.document).hide(); } catch (e) { } $("#dvProgress").show(); $("#dvProgress").fadeOut(15000); } 

我可以用excel格式下载报表,但不能在下载excel后从代码后面调用HideLoading2()函数。

保存时(“Report1”); 方法被评论,能够调用HideLoading2()。

这是保存方法

 public void save(string ReportName) { Warning[] warnings; string[] streamids; string mimeType, encoding, extension, deviceInfo; string format = "Excel"; byte[] bytes = null; deviceInfo = "True"; bytes = rptViewer.ServerReport.Render("EXCEL", null, out mimeType, out encoding, out extension, out streamids, out warnings); Response.Buffer = false; //transmitfile self buffers Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "GetReport/excel"; Response.AddHeader("Content-Disposition", "attachment; filename=" + ReportName + ".xls"); Response.OutputStream.Write(bytes, 0, bytes.Length); Response.OutputStream.Flush(); Response.OutputStream.Close(); Response.Flush(); Response.Close(); } 

下载Excel表格后,如何调用HideLoading2()函数?

注意:我没有在页面中使用scriptmanager \ updatepanel。

一旦调用了文件下载时需要的Response.Flush()和Response.Close(),服务器将停止处理并返回响应。 之后,你没有select执行代码。

通常为了下载文件,请尝试通过JavaScriptasynchronous调用函数,并使用window.open打开文件。