Hi, I have created sme asp pages that contains GridViews and charts and Buttons, I would like to add a "print " or "export to pdf oe excel" button in order to print he page without buttons (only GridViews and charts)
You can use Window.Print() javascript function for printing the document. And if you don't want to print the button you can hide the button using CSS, you need to apply like this
Just before you initiate the Print function or call any function behind the print button, just hide the button using css display:none or visible:false.
salim20001
Member
154 Points
507 Posts
Printing button on a page
May 06, 2012 01:12 PM|LINK
Hi, I have created sme asp pages that contains GridViews and charts and Buttons, I would like to add a "print " or "export to pdf oe excel" button in order to print he page without buttons (only GridViews and charts)
do you have any solutions?
Thanks
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Printing button on a page
May 06, 2012 01:20 PM|LINK
if you want to print just the grid and charts put them in div
<div id="ReceiptDiv">
your content here
</div>
<script type="text/javascript"> function printPartOfPage(elementId) { var printContent = document.getElementById(elementId); var windowUrl = 'about:blank'; var windowName = 'Print'; var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0'); printWindow.document.write(printContent.innerHTML); printWindow.document.close(); printWindow.focus(); printWindow.print(); printWindow.close(); } </script><asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="JavaScript:printPartOfPage('ReceiptDiv');return false;" />
salim20001
Member
154 Points
507 Posts
Re: Printing button on a page
May 06, 2012 02:35 PM|LINK
Thank you, however when I print: the gridviews appear and the chart doesn't appear (a blank image )
vsdev
Contributor
2230 Points
453 Posts
Re: Printing button on a page
May 06, 2012 03:59 PM|LINK
You can use Window.Print() javascript function for printing the document. And if you don't want to print the button you can hide the button using CSS, you need to apply like this
<style type="text/css"> @media print{ .button { display:none; } } </style>Hope it helps
Blog: dotnetthoughts
Download Capture It Plus
salim20001
Member
154 Points
507 Posts
Re: Printing button on a page
May 06, 2012 06:16 PM|LINK
Why the chatrs aren't displayed when I try to print ? (I'm using 3D charts )
Another problem, is when I print, I get the "localhost/MyWebsite/....." on the top of the page and I need to remove it
Bazinga
Member
19 Points
11 Posts
Re: Printing button on a page
May 06, 2012 09:34 PM|LINK
This code has proven to me. I had a similar problem.
http://weblogs.asp.net/infinitiesloop/archive/2007/09/25/response-redirect-into-a-new-window-with-extension-methods.aspx
kranthireddy...
Participant
790 Points
167 Posts
Re: Printing button on a page
May 07, 2012 02:07 AM|LINK
Hello salim,
I think this worked for me.
Just before you initiate the Print function or call any function behind the print button, just hide the button using css display:none or visible:false.
This should work.
Regards
Kranthi