Emad khan

Emad khan

  • 1.6k
  • 57
  • 42.4k

How to refresh current page after print window gets closed .

Feb 24 2014 7:55 AM
My Question is that : " I have a grid view in which there are 6 columns , last 2 columns are EDIT and DETAILS . Now i also have a PRINT Button outside the DATAGRID , what i want is that , when a user clicks on that Print Button, My Last 2 columns Edit and Details got hide, then the print window appears , then user will click on either Print or Close that window (if he wish to) . after that print window closes or being closed by a user ,then, that 2 columns which i hide when the PRINT btn was clicked , now gets visible ... so far i have tried this code , i am successful only in hiding the last two columns and not showing them in print preview , BUT ! after that print window is closed , my hided columns are not showing again .... i have to reload my page manually by pressing CTRL + F5 ... how to achieve this task ? I want to show those columns again ... Please help me ... here's my code on PRINT BTN CLICK EVENT ....

protected void PrintBTN_Click(object sender, EventArgs e) 
foreach (GridViewRow row in GridView1.Rows) 
{  
row.Cells[5].Visible = false;  
row.Cells[6].Visible = false; 
GridView1.Columns[5].Visible = false; 
GridView1.Columns[6].Visible = false; 
StringBuilder sb = new StringBuilder();  
sb.Append("<script type = 'text/javascript'>");  
sb.Append("function pageLoad(sender, args){");  
sb.Append("var prtContent = document.getElementById(\"divPrint\");");
sb.Append("var WinPrint = window.open('', '', 'letf=0,top=0,toolbar=0,scrollbars=0,status=0');");
sb.Append("WinPrint.document.write(prtContent.innerHTML);");  
sb.Append("WinPrint.document.close();");  
sb.Append("WinPrint.focus();");  
sb.Append("WinPrint.print();");  
sb.Append("WinPrint.close();}");  
sb.Append("</script>"); 
ScriptManager.RegisterClientScriptBlock(this, GetType(), "GridPrint", sb.ToString(), false); 
}

Answers (4)