Friday, 7 February 2014

Print Panel Using Javascript

Aspx Page:
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="PrintPanel();" />

 <script language="javascript" type="text/javascript">

                function PrintPanel() {
                    var panel = document.getElementById("<%=PanelResult.ClientID %>");
                  
                    // window.print();
                    var printWindow = window.open('', '');
                    printWindow.document.write('<html><head><title></title>');
                    printWindow.document.write('</head><body >');
                    printWindow.document.write(panel.innerHTML);
                    printWindow.document.write('</body></html>');
                    printWindow.document.close();
                    setTimeout(function () {
                        printWindow.print();
                    }, 500);

                    return false;
                }
            </script>