Click here to Skip to main content
12,350,326 members (27,260 online)
Rate this:
 
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 20:29pm
Edited 11-Sep-12 1:51am
_Amy55.6K
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.
ooffooooo 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
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 7 Sep 2013
Copyright © CodeProject, 1999-2016
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