How to set specify place for print preview and print using java script

In this article, we will discuss how to set print preview value and print the same in asp.net. Many projects we need to print some content not for that all the content so this article will be helping you.


Source code:-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="print.aspx.cs" Inherits="print" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        function printdivcontent(divId) {
            var printContent = document.getElementById(divId);
            var WinPrint = window.open('', '', 'left=0,top=0,toolbar=0,sta­tus=0');
            WinPrint.document.write(printContent.innerHTML);
            WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div id="printcontent">
            <h3>
                Content for  print
            </h3>
            <p>
                Sardar: What is the name of your car?<br />
                Lady: I forgot the name, but is starts with 'T'.<br />
                Sardar: Oh, what a strange car, starts with Tea. All cars that I know start with
                petrol.
                <br />
                <br />
              for more:-  http://www.livewithfun.in/
            </p>
        </div>
        <br />
        <div id="notprintcontent">
            <h3>
                Content for not print
            </h3>
            <p>
                when life Gets
                <br />
                TOo Hard TO STAnd
                <br />
                Kneel
                <br />
              for more:-  http://www.livewithfun.in/
            </p>
        </div>
        <br />
        <asp:Button ID="btnprint" runat="server" Text="Print" OnClientClick="javascript:printdivcontent('printcontent');" />
    </div>
    </form>
</body>
</html>



Out-Put:-



For more:-

How to set specify place for print preview and print using java script How to set specify place for print preview and print using java script Reviewed by NEERAJ SRIVASTAVA on 4:41:00 PM Rating: 5

No comments:

Powered by Blogger.