Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am doing Restarunt project. I want to print Bill when i click the button onthe webpage.Please any simple idea for print. Thank you

I am using Asp.net with C#
Posted

 
Share this answer
 
 
Share this answer
 
Comments
devausha 21-Mar-12 7:43am    
I want print text to notepad dynamically and then send file to printer
Member 8763905 12-Mar-13 7:02am    
I have one .aspx page from which I want to print some part
use this script 
1)

XML
<script language="javascript" type="text/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,status=0');
        WinPrint.document.write(prtContent.innerHTML);
        WinPrint.document.close();
        WinPrint.focus();
        WinPrint.print();
        WinPrint.close();
        prtContent.innerHTML = strOldOne;
    }
</script>

2)
XML
<div id ="bill">
<%-- the content will be printed --%>.


3)call the Function 

C#
<asp:button id="BtnPrint" runat="server" text="Print" onclientclick="javascript:CallPrint('bill');" xmlns:asp="#unknown" />
</div>
 
Share this answer
 
v2
Comments
Nickey Lay 5-Sep-19 5:38am    
Hello Brother thank you for your Method That is amazing. :) I need little bit
request to you :) How to print listbox item( not border ) Only text inside listbox ?
For example, listbox have three item Apple , mango, Orange , if I click print, just only
Apple
mango
Orange
not include listbox border :) thank all
try this code
ASP.NET
<asp:Button ID="printButton" runat="server" Text="Print" OnClientClick="javascript:window.print();" />
 
Share this answer
 
Comments
devausha 21-Mar-12 6:46am    
I want to creating Bill format at runtime like prn file and then that file is printed. How to do it.
JavaScript
function printwindow()
      {
       document .getElementById('<%=lnkprint.ClientID%>').style.visibility= "hidden";
       document .getElementById('<%=lnkExport.ClientID%>').style.visibility= "hidden";

       window.print();
       document .getElementById('<%=lnkprint.ClientID%>').style.visibility= "visible";
       document .getElementById('<%=lnkExport.ClientID%>').style.visibility= "visible";


      }


ASP.NET
<asp:linkbutton id="lnkprint" runat="server" text="Print" onclientclick="printwindow();"
                            ForeColor="Blue" />
 
Share this answer
 
v3
try this link
Custom print
 
Share this answer
 
Comments
kareem salem 21-Mar-12 7:05am    
or this

http://www.eggheadcafe.com/tutorials/asp-net/ed88bcef-0f0e-415c-9674-763806da1f43/print-web-page-in-aspnet-20.aspx
I suppose you want to print only a part of the page.
I would suggest to put your control in a pannel.
Following is the code.
JavaScript
<script type="text/javascript">
    function PrintTextbox() {
        var text_box = document.getElementById("<%=Panel1.ClientID %>");
        var printWindow = window.open('', '', 'height=400,width=800');
        printWindow.document.write('<html><head><title>Name of File</title>');
        printWindow.document.write('</head><body >');
        printWindow.document.write(text_box.innerHTML);
        printWindow.document.write('</body></html>');
        printWindow.document.close();
        setTimeout(function () {
            printWindow.print();
        }, 500);
        return false;
    }
    </script></script>


Hope this helps..
 
Share this answer
 
Comments
CHill60 30-Mar-14 11:58am    
You are two years and 6 solutions late on this one
If your printer supports ESC/POS (EPSON printer lang) then you can directly print to the client printer from your ASP.NET page by following this code or this other one. The first one is not free and requires you install an utility at the client machine. The second one, is open source and limited to community mail list support (or you can pay for personal support) and requires JAVA VM installed at the client machine.
 
Share this answer
 

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