Click here to Skip to main content
12,457,938 members (50,271 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript
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 :
imgBtnPrint.Attributes.Add("onclick", "window.print();");

how to do this ?
Thanks in advance
Posted 14-Feb-12 23:31pm
Updated 16-Feb-12 19:08pm
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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>
  Permalink  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

use this,
<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" />

hope this will help you.
And Don't forget to mark as answer if it helps. Smile | :)
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 17 Feb 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100