Click here to Skip to main content
15,212,119 members
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
Updated 16-Feb-12 19:08pm
Rate this:
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:
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)

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