Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello!!!

I have a panel whose contents i am printing by using a javascript function.

The function is
C#
function printform()
        {
             var printContent = document.getElementById('<%= pnl1.ClientID %>');
             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();
        }


It's working fine but when i am printing In page header Page 1 of 1 gets print and in page footer the url of the page and date gets print. how should i stop them from printing??
Posted

Hi ,
Check this
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>


XML
<div id ="bill">
<%-- the content will be printed --%>
</div>
<asp:button id="BtnPrint" runat="server" text="Print" onclientclick="javascript:CallPrint('bill');" xmlns:asp="#unknown" />

Best regards
M.Mitwalli
 
Share this answer
 
Comments
ujjwal uniyal 6-Sep-12 2:18am    
I can't get it to work as the panel in on the same page on which the form is. So when clicking the print button the validations on the forms are getting fired. I have set the event validation of the button to false but the are firing still.
ujjwal uniyal 6-Sep-12 2:33am    
It's still printing the page no and the url of the page....
Mohamed Mitwalli 6-Sep-12 2:41am    
only the content is printed isn't and yes url is printed
ujjwal uniyal 6-Sep-12 2:47am    
yeah!!! the url and Page no is getting printed. I don't want them to get printed as then i can print this panel again on the same page under the panel printed earlier. This will save paper sheets..

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