Search code examples
jqueryhttp-redirectiframepopupresponse.write

trigger download from iFrame in .NET


Ok so bear with me here. I have an umbraco site which has an external control embedded in it (an ascx file and a dll).

I'm mentioning that it's umbraco so that you know we have no control over most aspects of the page lifecycle, otherwise it shouldn't matter.

The control appears on a modal popup window within an iframe and it's just a form. When you submit the form an email is sent in the code behind and then I want to trigger a PDF download and few seconds later close the modal pop up.

So far this is proving impossible. It seems Response.End() seems to interrupt the control postback. I also tried Response.Flush() or tried without it altogether. Nothing has worked.

Is there way to trigger a download and then continue with the postback? I tried redirecting but I get a redirect error which makes sense that after a response.End() it's impossible to redirect.

I also tried a jQuery only solution (jQuery.fileDownload.js) but that doesn't work because of Umbraco's limitations (cannot add the cookie header on the page).

Running out of options here. Any suggestion is very welcome


Solution

  • For example, you can try to move the code that manages download to a standalone control (or httphandler) and invoke it from js on form submit like this

    $("#yourform").submit(function() {
        $('<form action="/pathtoyourhandler.ashx" method="POST"></form>')
        .appendTo('body').submit().remove();
    });
    

    (that's actual code from our umbraco project)