Link to home
Start Free TrialLog in
Avatar of jglazer63
jglazer63

asked on

Print a panel in asp.net/vb.net

Is there a quick and dirty way to add a print button to a web form such that it will allow the user to print the contents of just one panel on the form?  VB  if you please if possible
ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jglazer63
jglazer63

ASKER

Well this is close but something is screwy.  When I hit the print button it opens another window but it renders the entire page.  Well to be more precise, it renders most of the page most of the time, other times it only renders a piece.  I've even seen it get distorted.  I know I coded the ID of the panel alone.  Any ideas here?
Nevermind.  I worked it out.  It seems that even though you ID the panel as "Panel1" when it is created in HTML its ID becomes "ctl00_pvt_main_Panel1".  If I use that ID all is well.  

Thanks for the help!!
I am using similar code trying to print contents of a panel. Basically within the panel I have an image that is 2550 X 3300 which is the size of a 8 X 11 sheet of paper. The only issue that I am having is that when it prints there is a blank 2nd page. Do you have any idea of how to fix this issue?

</head>
       <script type = "text/javascript">
           function PrintPanel() {
               var panel = document.getElementById("<%=pnlContents.ClientID%>");
               var printWindow = window.open('', '', 'height=400,width=800');
               printWindow.document.write('<html><head><title>                      </title>');
               printWindow.document.write('</head><body >');
               printWindow.document.write(panel.innerHTML);
               printWindow.document.write('</body></html>');
               setTimeout(function () {
                printWindow.print();
            }, 500);
            return false;
        }
    </script>