Click here to Skip to main content
15,885,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i anm getting error in this code .. what is my mistake???
ASP.NET
 <script type="javascript" language="javascript">
        function Clickheretoprint() {
            var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
            disp_setting += "scrollbars=yes,width=650, height=600, left=100, top=25";
            var content_vlue = document.getElementById("print_content").innerHTML;

            var docprint = window.open("", "", disp_setting);
            docprint.document.open();
            docprint.document.write('<html><head><title>Inel Power System</title>');
            docprint.document.write('</head><body onLoad="self.print()"><center>');
            docprint.document.write(content_vlue);
            docprint.document.write('</center></body></html>');
            docprint.document.close();
            docprint.focus();
        }
</script><asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick = "javascript:Clickheretoprint()"
                             Height="29px" 
                            style="font-weight: 700" Width="70px" />
Posted
Updated 11-Sep-12 1:51am
v2
Comments
Peter_in_2780 11-Sep-12 3:35am    
Which line is getting the error? Look back to see what you are using on that line that hasn't been set up. For example, if window.open fails, then docprint will be null, and the next line will get the error you describe.
Mohammed Abdul Muqeet 11-Sep-12 3:47am    
here its showing some yellow tag--->> javascript:Clickher
the same code is working in one page but in my transaction page its showing error ..
Himanshu Yadav 11-Sep-12 6:46am    
I think this line throwing Exception
document.getElementById("print_content").innerHTML;
Don't use innerHtml
Use .Value
It will work fine
Member 10584413 17-Feb-14 5:53am    
yaaaaaaaaaaa
Member 10584413 17-Feb-14 5:52am    
ada ponaga da

Hi,
As I think, you are missing ";" semicolon while calling the javascript function that's why it is not able to call the function.
Try this:
ASP.NET
<asp:button id="btnPrint" runat="server" text="Print" onclientclick="javascript:Clickheretoprint();" height="29px" style="font-weight: 700" width="70px"/>

Or
ASP.NET
<asp:button id="btnPrint" runat="server" text="Print" onclientclick="Clickheretoprint();" height="29px" style="font-weight: 700" width="70px" />



--Amit
 
Share this answer
 
v2
declare a hidden field variable and store the value to hiddenfield variable and print from that variable as i modified the code

JavaScript
<script type="javascript" language="javascript">
        function Clickheretoprint() {
            var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
            disp_setting += "scrollbars=yes,width=650, height=600, left=100, top=25";
           // var content_vlue = document.getElementById("print_content").innerHTML;
  var content_vlue = document.getElementById("hiddenfieldID").value;
            var docprint = window.open("", "", disp_setting);
            docprint.document.open();
            docprint.document.write('<html><head><title>Inel Power System</title>');
            docprint.document.write('</head><body  önload="self.print()"><center>');
            docprint.document.write(content_vlue);
            docprint.document.write('</center></body></html>');
            docprint.document.close();
            docprint.focus();
        }
</script>

Hope this will work
 
Share this answer
 
v3
script type="javascript" language="javascript">

Change this line to

script language="javascript" type="text/javascript">
 
Share this answer
 
JavaScript
<html>
<head>

 <script type="text/javascript">
        function Clickheretoprint() {
            var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
            disp_setting += "scrollbars=yes,width=650, height=600, left=100, top=25";
            var content_vlue = document.getElementById("print_content").innerHTML;
 
            var docprint = window.open("", "", disp_setting);
            docprint.document.open();
            docprint.document.write('<html><head><title>Inel Power System</title>');
            docprint.document.write('</head><body onLoad="self.print()"><center>');
            docprint.document.write(content_vlue);
            docprint.document.write('</center></body></html>');
            docprint.document.close();
            docprint.focus();
        }
</script>
</head>
<body>

<input type="button" value="Print" ID="btnPrint"  Text="Print" onclick = "Clickheretoprint()"  />
<div id="print_content">Hello!!! Please print me</div>
</body>
</html>
 
Share this answer
 

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