Click here to Skip to main content
13,087,941 members (64,641 online)
Rate this:
Please Sign up or sign in to vote.
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
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

script language=javascript>
function CallPrint(strid)
 var prtContent = document.getElementById(strid);
 var WinPrint ='','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,sta­tus=0');

<div id="divPrint">
//print all from this content 
<asp:button ID="imgBtnPrint" onClick="javascript:CallPrint('divPrint');"
Runat="Server" /></div>
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
Please Sign up or sign in to vote.

Solution 2

use this,
<head runat="server">
    <style type="text/css" media="screen">
    <style type="text/css" media="print">
    <form id="form1" runat="server">
        <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. :)
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 |
Web03 | 2.8.170813.1 | Last Updated 17 Feb 2012
Copyright © CodeProject, 1999-2017
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