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
1 Answer
Reset to default 3thats 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条)