Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am desigining a web application,in which i have a PRINT button.When I press that button,I am retrieving values from database. But I dont know how to send these values to print.
I have found that PrintDialog will work for window application but not for web application and window.print() is priting entire page.

I have to print only perticular values in an order , for example , Printing a Demand Draft(or Bankers Check).

Need help.

Thanks.
Posted

1 solution

you can do print job with css and javascript.
window.print() is a javascript function which printing an area.
you can determine your area with css

firstly define your css classes at page

CSS
<style type="text/css" media="print">
    .printThis {display: block;}
    .noPrint {display: none;}
</style>


use noPrint css class for which html area you dont want to print
and use printThis css class which html tag you want to print
 
Share this answer
 
Comments
Sandeep Mewara 8-May-12 9:15am    
5!
Naveen_143 9-May-12 1:18am    
Thanks Dain. I completely forgot about using CSS for this issue.Your answer helped .
Naveen_143 10-May-12 2:42am    
Hi Dain, need one more help. I am able to print the values but image present in master page is also getting printed. I want only values present in the content page. is there a way for that..???
Dain Ucak 10-May-12 3:43am    
ok look that
<table class='printThis'><tr><td>This will print</td></tr>
<tr><td class='noPrint'><img src='' />this wont print</td></tr>
</table>
i hope this will help. if not enough please share your pages html code.
Naveen_143 10-May-12 4:37am    
Sorry Dain,I dint get what you are tyring to explain.This is my code--->

<%@ Page Language="VB" MasterPageFile="~/XDFE.master" AutoEventWireup="false" CodeFile="PrintDD.aspx.vb" Inherits="PrintDD" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<style type="text/css" media="print">
.printThis {display: block;}
.noPrint {display: none;}
.style1
{
width: 494px;
}
</style>
<script type="text/javascript">
function printpage()
{
window.print()
}
</script>




<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
 <div class ="printThis" style ="width :500px; height :220px ; border :thin groove black">

<table style="width: 499px; height: 220px">
<tr><td class="style1"><asp:Label ID ="lblHeader" runat ="server" Text="DemandDraft" ></td></tr>
<tr><td align ="right" class="style1"><asp:Label ID="lblDate" runat ="server" style="position :relative "></td></tr>
<tr><td align ="left" class="style1"><asp:Label ID="lblFav" runat ="server" style="position :relative "></td></tr>
<tr><td align ="left" class="style1"><asp:Label ID="lblPaybrn" runat ="server" style="position :relative "></td></tr>
<tr><td align ="right" class="style1"><asp:Label ID="lblAmount" runat ="server" style="position :relative "></td></tr>
<tr><td align ="center" class="style1"><asp:Label ID="lblprefix" runat ="server" style="position :relative "></td></tr>

</table>
</div>
<table >
<tr><td align ="center" ><asp:Button ID="btnPrint" runat ="server" Text="PrintDD" OnClientClick="printpage()" /></td></tr>
<tr><td align ="center" ><asp:Button ID="btnBak" runat ="server" Text="Back" /></td></tr>

</table>





This is the page i am printing. That <div> is printing properly. But with that, masterpage image is also printing. I want only content page to be printed.

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