You must Sign In to post a response.
  • Category: .NET

    Printing driectly from asp page

    how to print data directly from page with the data(textbox data) for billing system without generating reports.
  • #648655
    You can use the javascript print for the same.


    <form id="Form1" method="post" runat="server">
    <div id="Div1">
    Printable content
    </div>
    <input type="button" value="Print" onclick="JavaScript:printPartOfPage('Div1');">

    <script type="text/javascript">
    <!--
    function printPartOfPage(elementId)
    {
    var printContent = document.getElementById(elementId);
    var windowUrl = 'about:blank';
    var uniqueName = new Date();
    var windowName = 'Print' + uniqueName.getTime();
    var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');

    printWindow.document.write(printContent.innerHTML);
    printWindow.document.close();
    printWindow.focus();
    printWindow.print();
    printWindow.close();
    }
    // -->
    </script>

    </form>

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #648679
    Please check the following code:


    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function CallPrint(strid)
    {
    var prtContent = document.getElementById(strid);
    var WinPrint = window.open('','','left=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();
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <div id="div1">
    print this only.
    </div>
    <input type="button" name="btnPrint" value="Print" onClick="javascript:CallPrint('div1');" Runat="Server" />
    </div>
    </form>
    </body>
    </html>


    Thanks & Regards
    Paritosh Mohapatra
    Microsoft MVP (ASP.Net/IIS)
    DotNetSpider MVM

  • #648689
    Please check below code:

    To print a web page, you can use code like this:

    <input type="button" value="Print" onclick="window.print();">

    This HTML code will return a Print button.


    This example use window.print() method. This method will print your complete web page

    Regards
    Mr.Rajesh
    Software Engg.


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.