If you need to send (back) your form to a new window, you can try to change the shape of the target to fake, for example:
var form = $("form"); form.attr("target", "__foo");
Submit a form.
form.submit();
And delete the target (setitmeout (, 1) - place the event at the end of js "event-queue", in our case, after sending the form):
setTimeout(function () { form.removeAttr("target"); }, 1);
In addition, before submitting, you can try to open a window with the __foo identifier for a more stylish design, and the form will be sent (postback) in this window instead of a new one:
var wnd = window.open('', '__foo', 'width=450,height=300,status=yes,resizable=yes,scrollbars=yes');
But I have no idea how to handle the provided window and catch the onload or jquery event. If you can do this, exchange a workaround and call wnd.print (); You can play with an iframe inside this wnd and maybe you will find a solution.
Updated:
Try looking at this prototype [tested in Chrome]:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.0.min.js"></script> <script type="text/javascript"> function PrintResult() { var wnd, checker, debug; debug = true; </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Button runat="server" ID="ReportButton" OnClick="ReportRenderClick" Text="Export to PDF" OnClientClick="PrintResult()"/> <asp:Button runat="server" Text="Just a button."/> </div> </form> </body> </html>
And here is the .cs file:
public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void ReportRenderClick(object sender, EventArgs e) { Response.Clear(); Thread.Sleep(2000); Response.ContentType = "application/pdf"; Response.WriteFile("d:\\1.pdf");