Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
I have to print .aspx page on which i have 3 image buttons on the window. these are Print,Export to Excel and Close.
When i click on print image button, then it also print buttons on that page. I am using this code for printing :
C#
imgBtnPrint.Attributes.Add("onclick", "window.print();");


how to do this ?
Thanks in advance
Posted
Updated 16-Feb-12 19:08pm
v3

C#
script language=javascript>
function CallPrint(strid)
{
 var prtContent = document.getElementById(strid);
 var WinPrint =
window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,sta­tus=0');
 WinPrint.document.write(prtContent.innerHTML);
 WinPrint.document.close();
 WinPrint.focus();
 WinPrint.print();
 WinPrint.close();
 prtContent.innerHTML=strOldOne;


}
<div id="divPrint">
//print all from this content 
</div>
<asp:button ID="imgBtnPrint" onClick="javascript:CallPrint('divPrint');"
Runat=Server /></div>
 
Share this answer
 
Comments
Manish.Insan 17-Feb-12 0:28am    
This code i have been applied but it is creating problem because there are 17-18 columns on the page, and when i go for print then it print the page in 3-4 pages.
use this,
ASP.NET
<head runat="server">
    <title></title>
    <style type="text/css" media="screen">
        .button
        {
            border:1px;            
         }
    </style>
    <style type="text/css" media="print">
        .button
        {
            display:none;
         }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <img src="Upload/WaterMarkImages/Chrysanthemum.jpg" height="400px" />
        <asp:button id="imgBtnPrint" onclientclick="javascript:window.print();" runat="Server" cssclass="button" xmlns:asp="#unknown">
            Text="Print" />
    </asp:button></div>
    </form>
</body>


hope this will help you.
And Don't forget to mark as answer if it helps. :)
 
Share this answer
 
Comments
Manish.Insan 17-Feb-12 0:37am    
same code i have written above. just you are calling that code from .aspx page. and I am calling from .cs page. Issue is, this print the button (Print, Close) on the print page.
Member 10253761 15-Sep-13 6:47am    
thanks bro it's working great
You save my time and energy
Mukund Thakker 17-Feb-12 1:35am    
please include the css which I have added in head section.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900