Solved

Print a panel in asp.net/vb.net

Posted on 2009-05-17
4
1,542 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

16 Experts available now in Live!

Get 1:1 Help Now