I'm trying to print the content of a div when the "Print" button is clicked. I keep getting this error: "Unable to set value of the property 'innerHTML': object is null or undefined." I read some posts over the Internet but I still can't find a working solution.
Here is my javascript code I use to print (got from here):
<script type="text/javascript">
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
</script>
My button event raises here:
<asp:Button ID="ButtonPrint" runat="server" Text="Print »" OnClientClick="printDiv('content');return false"></asp:Button>
And this is the div I'm supposed to print:
<div id="content" runat="server">
<h1 class="title" runat="server" id="formulario"></h1>
<asp:Table ID="TableForm" runat="server"></asp:Table>
<div id="TableQuest" runat="server">
</div>
<asp:Table ID="TableText" runat="server"></asp:Table>
<asp:Label ID="LabelInfo" runat="server" Text=""></asp:Label>
</div>
Any help would be greatly appreciated!