Click here to Skip to main content
15,889,367 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys..
I want to first my page print then redirect. I use below code but this code only redirect without page print. How can I solve this problem ?

C#
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "Script", "window.print();", true);

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "Script",window.location.href='Default.aspx';", true);


Thanks for helps.
Posted

1 solution

You can do the printing and redirect all via javascript. Here is an example that should work:
C#
function doPrint() {
    window.print();
    document.location.href = "Default.aspx";
}


Link it to a Button:
ASP.NET
<asp:button id="btnPrint" runat="server" text="Print" xmlns:asp="#unknown">
    OnClientClick="doPrint(); return false;" /></asp:button>
 
Share this answer
 
v2
Comments
truvali89 3-Feb-14 6:49am    
thanks for solution but my button was programmatically created. So I call javascript code in codebehind. How do I can?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900