繁体   English   中英

VB.net文件下载可防止回发

[英]VB.net file-download prevents postback

我想生成一个(报告)文件供用户下载,然后向用户显示一条消息,以显示该过程已成功完成。

Dim myFile As FileInfo = New FileInfo(<filepath>)

'My function to generate a report (this can take a few minutes)
GenerateReport(myFile.FullName)

'Prompt user with "save as" dialog box.
Response.Clear()
Response.ClearHeaders()
Response.AddHeader("Content-Disposition", "attachment; filename=" & _
Response.WriteFile()

'Give message to say generation is complete. (This line doesn't take effect)
lblMsg.Text = "Generation complete"

但是,当我使用“另存为”框时,似乎完全停止了该消息的显示。 这是为什么? 有人可以提出解决方法吗?

看来这是一个很普遍的问题。 但是对于我所遇到的所有建议,似乎很少能提供任何解决方案。 这是Rick Strahl博客中的有用文章

一种有用的方法是MyWebClient.DownloadFile 这样就可以正常下载文件,但不会根据需要提供“另存为”对话框。

暂无
暂无

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

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