简体   繁体   中英

VB.net file-download prevents postback

I want to generate a (report) file for users to download, then display a message to users to show the process completed successfully.

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"

However, when I use create a "save as" box, it seems to stop the message appearing at all. Why is that? And can anyone suggest a way around it?

It seems this is quite a common problem. But for all the suggestions I've come across, few seem to offer any sort of solution. Here's a useful article in Rick Strahl's blog .

One useful method is MyWebClient.DownloadFile . This downloads the file ok, but doesn't give a "save as" dialogue box as required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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