我从主页面菜单项调用.ashx文件下载excel文件。但这里混淆了用户。用户不知道下载是否发生。
如何在主页中点击菜单项时弹出进度条,下载后自动消失?
if e.Item.Text = "Download" Then
Dim strUrl As String = "../Users/Download.ashx"
ResponseHelper.Redirect(strUrl, "_black", "resizable=no, scrollbars=no")
end if
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'Some logic
Dim filename As String = "FullExtract_" & Now.Year.ToString & Now.Month.ToString & Now.Day.ToString & ".xlsx"
context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
context.Response.AddHeader("content-disposition", "attachment; filename=" & filename)
context.Response.BinaryWrite(pck.GetAsByteArray())
context.Response.End()
End Sub
答案 0 :(得分:0)
如果它不会干扰任何现有限制,您可以在页面中使用jQuery's .ajax()函数进行ajax调用并在该调用中处理客户端通知(粗略示例):
// Notify the user about downloading.
// Perform the download
$.ajax({
type: "POST",
url: '/Users/Download.ashx',
success: function(data) {
// Notify the user it's done.
}
});
答案 1 :(得分:0)
您可以从 here
获得这个想法