Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to download from modal dialog, window.showModalDialog
    primarykey
    data
    text
    <p>I am not able to download a file from a aspx page if aspx page is opened in a modal popup using window.showModalDialog().</p> <p>I have an image button on aspx page, on click of it a Excel file has been generated by using some business logic and then I add it to the Response header to make that file available for download. The code is as shown below,</p> <pre><code>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 </code></pre> <p>When I open this aspx page as a modal pop up it does not show the browser's download window. In case of normal(modeless, opened using window.open) popup download works fine.</p> <p>I have also tried using another approach for downloading files. Instead of setting response header in <code>ibtnExport_Click</code>, I have opened another aspx page, say Download.aspx, using <code>window.open</code> and set the repsonse headers on page load event of the Download.aspx. The code is as shown below,</p> <pre><code>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 </code></pre> <p>And in Download.aspx,</p> <pre><code>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 </code></pre> <p>Well, it works in case of both modal as well as modeless popup and gives a relife until you deploy the application on IIS :). Yes, this approach works on ASP.NET Development server but doesn't work on IIS.</p> <p>Any ideas, for making download work on modal popup windows?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload