Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP ASP.NET Javascript
i anm getting error in this code .. what is my mistake???
 <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 10-Sep-12 21:29pm
Edited 11-Sep-12 2:51am
_Amy51.5K
v2
Comments
Peter_in_2780 at 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.
ooffooooo at 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 at 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 at 17-Feb-14 5:53am
   
yaaaaaaaaaaa
Member 10584413 at 17-Feb-14 5:52am
   
ada ponaga da
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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:button id="btnPrint" runat="server" text="Print" onclientclick="javascript:Clickheretoprint();" height="29px" style="font-weight: 700" width="70px"/>
Or
<asp:button id="btnPrint" runat="server" text="Print" onclientclick="Clickheretoprint();" height="29px" style="font-weight: 700" width="70px" />
 

--Amit
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

declare a hidden field variable and store the value to hiddenfield variable and print from that variable as i modified the code
 
<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
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

script type="javascript" language="javascript">
 
Change this line to
 
script language="javascript" type="text/javascript">
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

<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>
 
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 195
3 DamithSL 195
4 Richard MacCutchan 178
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 7 Sep 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100