[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Print a panel in asp.net/vb.net

Posted on 2009-05-17
4
Medium Priority
?
1,616 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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