我有一个面板可以在 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>