Page.ClientScript.RegisterClientScriptBlock Window.Print not working in IE

1.9k Views Asked by At

Basically, I have this line of code that doesn't work in IE, but works in FF and Chrome just fine.

Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "RunPrintReport", "<script language='JavaScript'>window.print();</script>")

I don't get any errors, just doesn't work. If I change to

Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "RunPrintReport", "<script language='JavaScript'>alert('this is a test');</script>")

the alert comes up just fine, any idea why the window.print wouldn't work? I've also written into another function and tried just calling that function containing a window.print();return false; to no avail as well as just including that in the RegisterClientScriptBlock. No idea why it's not working

1

There are 1 best solutions below

0
Michael Biggs On

I took your code and modified it slightly. I took out your script tags and added True as the last parameter. Asp will generate the script tags for you.

Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "RunPrintReport", "window.print();",true);

I tried and this works in Chrome, I.E 10 and I.E 8. One note is when opening in Internet Exploder the print dialog took a couple seconds to open.