protected void Page_Load(object sender, EventArgs e) { if (!Page.User.Identity.IsAuthenticated) { FormsAuthentication.RedirectToLoginPage(); } if (!IsPostBack) { if (PreviousPage is DefaultScreen ds) { qcs.EmpID = ds.EmpID; qcs.PermID = ds.PermID; } else { Response.Redirect("~/DefaultScreen.aspx"); } QuoteGridView.DataBind(); PrintDetailsView.DataBind(); if (qcs.PermID < 4) { DeleteButton.Visible = true; } QuoteSelectedPanel.Visible = false; } if (QuoteGridView.SelectedIndex > -1) { PrintButton.Visible = true; } Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1)); Response.Cache.SetNoStore(); }
protected void PrintButton_Click(object sender, EventArgs e) { PrintDetailsView.DataBind(); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); Control parent = PrintDetailsView.Parent; int GridIndex = 0; if (parent != null) { GridIndex = parent.Controls.IndexOf(PrintDetailsView); parent.Controls.Remove(PrintDetailsView); } PrintDetailsView.RenderControl(hw); if (parent != null) { parent.Controls.AddAt(GridIndex, PrintDetailsView); } string gridHTML = sw.ToString().Replace("\"", "'").Replace(System.Environment.NewLine, ""); StringBuilder sb = new StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("window.onload = new function(){"); sb.Append("var printWin = window.open('', '', 'left=0"); sb.Append(",top=0,width=1000,height=600,status=0');"); sb.Append("printWin.document.write(\""); sb.Append(gridHTML); sb.Append("\");"); //sb.Append("printWin.document.close();"); sb.Append("printWin.focus();"); sb.Append("printWin.print();};"); //sb.Append("printWin.close();};"); sb.Append("</script>"); ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString()); PrintDetailsView.DataBind(); }