I have a custom solution where I open a SP Dialog box through Javascript. From this dialog, I want to generate a file and sent it to the user when he is clicking on a button, than close the dialog.
All the pieces of my puzzle are working individually, but when stitch together, the dialog box never close.
Sending the dynamic file (data) on button click:
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=Export.csv");
HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STREAM";
HttpContext.Current.Response.BinaryWrite(data);
HttpContext.Current.Response.Flush();
Works great, then I want to close my dialog box using the following code:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ClosingScript", "<script type=\"text/javascript\">window.frameElement.commonModalDialogClose(1, null);</script>");
It will not close the dialog. I removed the file generation and the dialog will close immediately. I've tried numerous combination of code, even handler and more JavaScript, without success. Maybe someone had some new/fresh idea for me?
Thanks!