JavaScript runtime error: Unable to get property 'innerHTML' of undefined or null reference in asp.net - Stack O

I have a textbox in which user will write some text.Now If he wants to print that text he should click

I have a textbox in which user will write some text.

Now If he wants to print that text he should click on print button. The design of Print button is as follows:

<asp:Button ID="btnPrint" runat="server" Text="Print" Enabled="False" OnClientClick = "CallPrint('txtReadFiles')" />

Now in the head part of aspx page the function CallPrint is declared as follows :

<script type="text/javascript" language="javascript">
        function CallPrint(strid)
        {
            var prtContent = document.getElementById(strid);
            **var docwrite=prtContent.innerHTML;**
            var WinPrint = window.open('','','left=0,top=0,toolbar=0,status=0');
            WinPrint.document.open();
            WinPrint.document.write(docwrite);
            WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();
            WinPrint.close();
        }
    </script>

But when I click on print button I get an error on line marked with **

JavaScript runtime error: Unable to get property 'innerHTML' of undefined or null reference

What is the problem here?

I have a textbox in which user will write some text.

Now If he wants to print that text he should click on print button. The design of Print button is as follows:

<asp:Button ID="btnPrint" runat="server" Text="Print" Enabled="False" OnClientClick = "CallPrint('txtReadFiles')" />

Now in the head part of aspx page the function CallPrint is declared as follows :

<script type="text/javascript" language="javascript">
        function CallPrint(strid)
        {
            var prtContent = document.getElementById(strid);
            **var docwrite=prtContent.innerHTML;**
            var WinPrint = window.open('','','left=0,top=0,toolbar=0,status=0');
            WinPrint.document.open();
            WinPrint.document.write(docwrite);
            WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();
            WinPrint.close();
        }
    </script>

But when I click on print button I get an error on line marked with **

JavaScript runtime error: Unable to get property 'innerHTML' of undefined or null reference

What is the problem here?

Share Improve this question asked May 12, 2013 at 21:41 VishalVishal 6,37814 gold badges89 silver badges164 bronze badges 3
  • 2 Do you have an element with the ID txtReadFiles ? – adeneo Commented May 12, 2013 at 21:45
  • And, if you have a txtReadFiles, what is it? – acdcjunior Commented May 12, 2013 at 21:57
  • Yes I have. It is a textbox – Vishal Commented May 12, 2013 at 23:00
Add a ment  | 

1 Answer 1

Reset to default 3

thats probably because this line var prtContent = document.getElementById(strid); fails i.e. returns null. is the textbox you are trying to get also a server control ? If so then during runtime its id would change ,if this indeed is the issue look here

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742252907a4409486.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信