Solved

Print a panel in asp.net/vb.net

Posted on 2009-05-17
4
1,527 Views
Last Modified: 2015-10-30
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
0
Comment
Question by:jglazer63
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 500 total points
ID: 24408934
Hi jglazer63,
>>..will allow the user to print the contents of just one panel on the form
Yes, you can just create a new dummy pop-up window and include the rendered HTML content that resides inside panel that you need. That is the easier way to print out the preferred content in the web page. You can modify it based on your real output that needed.
<html>

<script type="text/javascript">

function printMe()

{

var content=document.getElementById('yourPanelClientID');
 

//open blank page and put the rendered HTML text inside

w=window.open('about:blank');

w.document.open();

w.document.write("<html>" + content.innerHTML);

w.document.writeln("<script>window.print()</"+"script>");

w.document.writeln("</html>");

w.document.close();

}

</script>

Other Content bla bla bla <br>

<div id="yourPanelClientID">

YOUR Panel Content here in web form ...

</div>

<input type=button id=btn onclick="printMe()" value="Print">

</html>

Open in new window

0
 

Author Comment

by:jglazer63
ID: 24411463
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?
0
 

Author Closing Comment

by:jglazer63
ID: 31582469
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!!
0
 
LVL 2

Expert Comment

by:Thomas Swaney
ID: 41152045
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>
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now