I cannot download a file from an aspx page if the aspx page is open in a modal popup using window.showModalDialog ().
I have an image button on an aspx page that I clicked on which an Excel file was generated using some business logic, and then I add it to the Response header to make this file available for download. The code is shown below.
Protected Sub ibtnExport_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnExport.Click
...
Some business logic to generate excel file.
...
Response.ClearHeaders()
Response.ContentType = "application/ms-excel"
Response.AddHeader("content-disposition", "attachment; filename=" + someXLSFile )
Response.TransmitFile(someXLSFileWithPath)
Response.Flush()
HttpContext.Current.ApplicationInstance.CompleteRequest()
End Sub
When I open this aspx page as a modal popup, it does not show the browser loading window. In the case of a normal (weak, open using window.open) popup, it works fine.
. , ibtnExport_Click, aspx, Download.aspx, window.open Download.aspx. ,
Protected Sub ibtnExport_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnExport.Click
...
Some business logic to generate excel file.
...
Session("$FileToDownload$") = someXLSFileWithPath
ClientScript.RegisterStartupScript(GetType(String),"download","window.open('Download.aspx')",true)
End Sub
Download.aspx,
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim filetoDownload As String = CType(Session("$FileToDownload$"), String)
Dim fileName As String = System.IO.Path.GetFileName(filetoDownload)
Response.ClearHeaders()
Response.ContentType = "application/ms-excel"
Response.AddHeader("content-disposition", "attachment; filename=" + fileName)
Response.TransmitFile(filetoDownload)
Response.Flush()
HttpContext.Current.ApplicationInstance.CompleteRequest()
End Sub
, , relife, IIS:). , ASP.NET, IIS.
?