I have an issue with my print page. When the user clicks the print button I have a print preview that pops up and shows how the page looks before it is printed. The logo takes up half of the page, the textboxes are not aligning right and the URL, Data, Time and Page numbers are on the print out. Is the a way to fix all of this?
This is the Code Behind that Page:
using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Drawing.Printing;
using System.IO;
using System.Web.SessionState;
namespace SACSCOCLogin1._1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con2.Open();
SqlConnection con3 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con3.Open();
TextBoxINST_ID.Text = Session["inst_id"].ToString();
SqlCommand scmd = new SqlCommand("Select INST_ID, LongName, City, State from Table22 where INST_ID = '" + TextBoxINST_ID.Text + "'", con);
SqlCommand scmd2 = new SqlCommand("Select INST_ID, TOTAL_REVE, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, SCHOLARSHI, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT from Table99 where INST_ID = '" + TextBoxINST_ID.Text + "'", con2);
SqlCommand scmd3 = new SqlCommand("Select INST_ID, accessLevel from Table33 where INST_ID = '" + TextBoxINST_ID.Text + "'", con3);
SqlDataReader dr = scmd.ExecuteReader();
SqlDataReader dr2 = scmd2.ExecuteReader();
SqlDataReader dr3 = scmd3.ExecuteReader();
if (dr.Read())
if (dr2.Read())
if (dr3.Read())
{
TextBoxaccessLevel.Text = dr3["accessLevel"].ToString();
lblCity.Text = dr["City"].ToString();
lblState.Text = dr["State"].ToString();
lblSchool.Text = dr["LongName"].ToString();
TextBoxInstr.Text = dr2["INSTRUCTIO"].ToString();
TextBoxRes.Text = dr2["RESEARCH"].ToString();
TextBoxPubS.Text = dr2["PUBLIC_SER"].ToString();
TextBoxAcad.Text = dr2["ACADEMIC_S"].ToString();
TextBoxStudS.Text = dr2["STUDENT_SE"].ToString();
TextBoxInstiS.Text = dr2["INSTITUTIO"].ToString();
TextBoxOperM.Text = dr2["PHYSICAL_P"].ToString();
TextBoxSFEDA.Text = dr2["SCHOLARSHI"].ToString();
TextBoxAuxE.Text = dr2["AUXILIARY_"].ToString();
TextBoxHosS.Text = dr2["HOSPITALS"].ToString();
TextBoxIndeO.Text = dr2["INDEPENDEN"].ToString();
TextBoxOED.Text = dr2["OTHEREXP"].ToString();
TextBoxTA.Text = dr2["TOTASSETS"].ToString();
TextBoxTL.Text = dr2["TOTLIABILITY"].ToString();
TextBoxNPRNA.Text = dr2["NoNEXPPERMRESASSETS"].ToString();
TextBoxTUNA.Text = dr2["UNRNETASSETS"].ToString();
TextBoxTR.Text = dr2["TOTALREV"].ToString();
TextBoxTFN.Text = dr2["TUITFEES"].ToString();
TextBoxCD.Text = dr2["CURRDEBT"].ToString();
TextBoxLTD.Text = dr2["LONGTERMDEBT"].ToString();
TextBoxTROA.Text = dr2["TOTAL_REVE"].ToString();
}
dr.Close();
con.Close();
dr2.Close();
con2.Close();
dr3.Close();
con3.Close();
}
protected void ButtonPrint_Click(object sender, EventArgs e)
{
Session["ctrl"] = Panel1;
ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('Print.aspx','PrintMe','height=300px,width=300px,scrollbars=1');</script>");
}
}
}
This the code for the Print Preview Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Print.aspx.cs" Inherits="SACSCOCLogin1._1.Print" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Here is the code behind that page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SACSCOCLogin1._1
{
public partial class Print : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Control ctrl = (Control)Session["ctrl"];
PrintHelper.PrintWebControl(ctrl);
}
}
}
When the Print Button is clicked it also refers to this page for the action.
Here is the code behind for this page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SACSCOCLogin1._1
{
public partial class Print : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Control ctrl = (Control)Session["ctrl"];
PrintHelper.PrintWebControl(ctrl);
}
}
}
Sorry for all the code but trying to make sure I don't miss anything. Thanks.