[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • 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)
0
genesisproject
Asked:
genesisproject
1 Solution
 
RogerSTHLMCommented:
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">

Cheers
R
0
 
TorrwinCommented:
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,";
                              sOption+="scrollbars=yes,width=750,height=600,left=100,top=25";
   
                  var winprint=window.open("print.aspx","Print",sOption);
 
                  winprint.focus();
                  }


            </script>
------------------------------------------------------------------------------------------------------------------

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

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>
   </form>
</div>

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:
<HTML>
      <HEAD>
            <script language="JavaScript">
                 function GetPrintContent()
                  {
                        var PrintDiv =  document.getElementById('printcontent');
                        var ContentDiv =  window.opener.document.getElementById('contentstart');
                        PrintDiv.innerHTML = ContentDiv.innerHTML;
                  }
            </script>
      </HEAD>
      <body onload="GetPrintContent();">
            <table cellSpacing="0" cellPadding="0" border="0" height="140" width="700" style="LEFT: 1px; POSITION: absolute; TOP: 15px">
                  <tr>
                        <td><IMG height="140" src="../images/template/osulogo.gif" width="700">
                        </td>
                  </tr>
            </table>
            <div id="printcontent">
            </div>
      </body>
</HTML>
------------------------------------------------------------------------------------------------------------

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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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