Exporting to Excel from a Modal IE Window

Posted on 2005-04-07
Last Modified: 2012-06-21
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.ContentType = "application/"
        Response.AddHeader("Content-Disposition", "attachment; filename=" & sFilename & "")

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.

Question by:gtmljsc
    LVL 14

    Accepted Solution

    Good question, maybe try getting tricky ... like putting an IFRAME in the modal window that loads the excel ... not sure of why it does not load offhand but try some quick workarounds to see if there is a way to hack it and get it to do what you want it to do.

    Does it have to be a modal window? Can a normal window with some javascript accomplish the same thing?
    LVL 1

    Author Comment

    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?

    LVL 1

    Author Comment

    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.
    LVL 14

    Expert Comment

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

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Suggested Solutions

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now