Solved

Print a panel in asp.net/vb.net

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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

696 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