Click here to Skip to main content
16,013,338 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
Hi,
I am having same javascript as below and I am using that in my Master Page.
But when I try to print;
It is showing me error on line:-
printWindow.document.write(printContent.innerHTML);

Thanks.

 <script type="text/javascript">
                function printPartOfPage() {
                    var printContent = document.getElementById("ContentPlaceHolder2");
                    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>


<div id="body">	
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">

</div>


HyperLink9.NavigateUrl = "javascript:window.printPartOfPage()";
HyperLink9.Text = "Print this Page";
Posted
Updated 18-May-12 6:30am
v2

1 solution

do this pls

C#
NavigateUrl="javascript:window.printPartOfPage(this)"

and pre configure your function that
JavaScript
function printPartOfPage(strid) {
             var printContent = strid;
             
                    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();
                }


i tried it worked
 
Share this answer
 
Comments
Member 8610379 18-May-12 12:53pm    
Thank you Sir,
For Reply.
It is not generating any error and also it is printing but it is not printing content, but it is just printing blank page.
I have used Ajax controls in my "Content Place Holder". It is having different tabs.
Dain Ucak 18-May-12 12:57pm    
you revized your codes. i discern after answering sorry. put your contentplaceholder in a div. and call this div in this scope in javascript
you have a body id of div. use it
var printContent = document.getElementById("body");
runat server controls generating different ids for html pages. but contentplaceholder id doesnt generate and id.
Member 8610379 29-May-12 15:00pm    
Thanks a lot Sir,
It is working exactly, as I want.

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