• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

printing my web pages

I created an online invoice (aspx) for the user to print out, but when I print out the information part of my invoice gets cut off (right side).  Is there a way in .net that all my information will get captured. ( I am using the print button on the browser)
1 Solution
No. Asp.net runs on server side. It has no idea when printing occurs.

However you can use a seperated style sheet used when printing occur. Use following syntax....
<LINK rel="stylesheet" type"text/css"  href="youStyleSheetPrintFile.css" media="print">

This is what I did, because I had a navigation menu on the left, and it was pushing my form off the printable area of the page.

I added this to the html header section of my aspx page:

<script Language="JavaScript">
                  function PrintThisPage()
                  var sOption="toolbar=no,location=no,directories=no,menubar=yes,";
                  var winprint=window.open("print.aspx","Print",sOption);


And this is the link on the navigation menu to get to the print page:
     <td><a href="javascript:PrintThisPage();"><IMG height="29" alt="Printer Friendly Version"  src="../images/template/printpreview.gif" width="158" border="0"></a></td>

When a user clicks the print link, it will open the "Print.aspx" page via the function above.

Now, here's the important part.  You need to put the tag <div id="contentstart"> </div> around the content on your original page that you want printed.  The sub will send the part of the webpage enclosed by the "div" tag over to the Print.aspx page.
For example, I placed mine around the form elements like this:

<div id="contentstart">
   <form id="Form1" method="post" runat="server">
        <asp:label id="lblTitle" style="Z-INDEX: 101; LEFT: 247px; POSITION: absolute; TOP: 176px" runat="server" Font-Underline="True" Font-Size="X-Large" Font-Bold="True">License Report</asp:label>&nbsp;
        <asp:label id="lblLicense" style="Z-INDEX: 102; LEFT: 86px; POSITION: absolute; TOP: 309px" runat="server"></asp:label>

This way, everything on my form that is asp code gets printed.

Now you create a "Print.aspx" page.

The Print.aspx page is just a blank page with the following as its html code:
            <script language="JavaScript">
                 function GetPrintContent()
                        var PrintDiv =  document.getElementById('printcontent');
                        var ContentDiv =  window.opener.document.getElementById('contentstart');
                        PrintDiv.innerHTML = ContentDiv.innerHTML;
      <body onload="GetPrintContent();">
            <table cellSpacing="0" cellPadding="0" border="0" height="140" width="700" style="LEFT: 1px; POSITION: absolute; TOP: 15px">
                        <td><IMG height="140" src="../images/template/osulogo.gif" width="700">
            <div id="printcontent">

So, when the user opens the print.aspx page, whatever is displayed on your original form (between the "div" tags) will be transferred over to, and displayed on the print.aspx page.  The user can then select print from the internet explorer menu. =)

I hope this helps, like I said my form was getting cut off on the right b/c I had the navigation menu on the left.  Yours may not be set up the same way.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now