Link to home
Start Free TrialLog in
Avatar of gtmljsc
gtmljsc

asked on

Exporting to Excel from a Modal IE Window

I have the following code to export binary data in a modal window that is opened using javascript window.showmodaldialog():

        Dim result() As Byte
        ...
        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = "application/vnd.ms-excel"
        Response.AddHeader("Content-Disposition", "attachment; filename=" & sFilename & "")
        Response.BinaryWrite(result)
        Response.End()

The problem is that it opens a blank window where it opens up the Save/Open dialog.  And I do not want another window opening up.  Everything works fine when I try to export from an ordinary window.

I've tried putting <base target=_self> in my aspx file.  What happens is the modal window seems to just refresh itself, but the Save/Open dialog doesn't appear anymore.

Help please.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of dfu23
dfu23

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gtmljsc
gtmljsc

ASKER

Our client wants it to be a modal window.

Anyways, here's what I really have:  

I do have an IFrame in my modal window, and it's created at runtime.  The content of the IFrame is a report generated by SQL 2000 Reporting Service.  Outside the IFrame is a an Export Button, which calls another method to render the report in Excel format, output as  binary data into my byte variable, result.  And then I use the code above to "export" the data as an Excel file.

I tried creating another IFrame F2, and putting <base target="F2"> in my aspx page.  It didn't work still.  It still opens up a new window.

Should my button be inside another iFrame?  If it is inside another IFrame, can it still access the query strings passed on to the main modal window?

Thanks.
Avatar of gtmljsc

ASKER

Everything's working now... I had to put my button inside another IFrame and call my export function from there.  But I also had to retransfer my query string again to the page in my new IFrame.  It's pretty messy, but it works!

Thanks dfu23.
No problem ... glad you were able to get to work!