Microsoft JScript运行时错误:无法获取属性'的值;innerHTML':对象为null或
Microsoft JScript runtime error: Unable to get value of the property 'innerHTML': object is null or undefined
我有一个面板要在asp.net中打印。我尝试了很多java脚本代码,但一直都会出现内部html错误。以下是代码。错误代码
Microsoft JScript runtime error: Unable to get value of the property 'innerHTML': object is null or undefined
按钮代码
<asp:Button ID="Savebutton" runat="server" OnClick="Button1_Click" OnClientClick="return PrintPanel();"/>
java脚本代码
function PrintPanel() {
var panel = document.getElementById("<%=pnlContents.ClientID %>");
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head><title>DIV Contents</title>');
printWindow.document.write('</head><body >');
printWindow.document.write(panel.innerHTML);
printWindow.document.write('</body></html>');
printWindow.document.close();
setTimeout(function () {
printWindow.print();
}, 500);
return false;
}
我想打印的div
<div id="printdiv" class="printable" runat="server">
<asp:Panel ID="pnlContents" runat="server">
<asp:Label ID="Label9" runat="server" Text="Medical Record No"></asp:Label>
<asp:Label ID="MRNLBLp" runat="server"></asp:Label>
<br />
<asp:Label ID="Label4" runat="server" Text="Patient Name"></asp:Label>
<asp:Label ID="Namelblp" runat="server"></asp:Label>
<br />
<asp:Label ID="Label6" runat="server" Text="Visit Date"></asp:Label>
<asp:Label ID="visitdatelblp" runat="server"></asp:Label>
<br />
<asp:Label ID="Label10" runat="server" Text="Symptoms"></asp:Label>
<asp:Label ID="symptomlblp" runat="server"></asp:Label>
<br />
<asp:Label ID="Label5" runat="server" Text="Test Prescribed"></asp:Label>
<asp:Label ID="testlblp" runat="server"></asp:Label>
</asp:Panel>
</div>
这很可能是因为以下行
var panel = document.getElementById("<%=pnlContents.ClientID %>");
未返回有效元素。我会调试它来验证
相关文章:
- 找到对象中值最高的键,然后将其发布到innerHTML中
- 'innerHTML':对象为空或未定义
- 如何在由 JavaScript 窗口对象打开的窗口中设置某些元素的 innerHTML
- TypeError:undefined不是一个对象(正在评估'msg.innerHTML="Uploa
- Microsoft JScript运行时错误:无法获取属性'的值;innerHTML':对象为null或
- IE8:“;ln.innerHTML要么为null要么不是对象”;
- 使用innerHTML来更改页面中动态创建的对象
- 附加对象到innerHTML,并从innerHTML获得该对象
- 对象标签添加innerHTML总是空的onload
- 为什么我的innerHTML对象没有改变时分配
- Internet Explorer的innerHTML对象不支持此属性或方法
- 从返回的表单对象中读取InnerHTML
- 当对象正在加载时,在innerHTML中显示LOADING
- javascript:如何插入对象到innerHtml
- 如何创建ActiveX's m_hWnd HWND,同时使用InnerHTML生成对象
- 如何将对象传递给innerHTML (JavaScript)中的函数
- Javascript对象.innerHtml没有替换所提供的整个字符串参数
- 通过jQuery选择器从对象中获取innerHTML
- innerHTML在jQuery对象上使用时不能正常工作
- 我如何从innerHtml创建一个jQuery对象