I am looking for a way to directly print the content of a reportviewer without saving it as a PDF, Excel, or Word file. After doing some research on Google, I found a solution that involves the following code:
<script language="javascript" type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
function printdiv(printpage) {
var headstr = "<html><head><title></title></head><body>";
var footstr = "</body></html>";
var newstr = document.getElementById(printpage).innerHTML;
var oldstr = document.getElementById("body1").innerHTML;
document.getElementById("body1").innerHTML = headstr + newstr + footstr;
window.print();
document.getElementById("body1").innerHTML = oldstr;
return false;
}
<div id="body1">
<input name="b_print" type="button" class="ipt" onclick="printdiv('div_print');" value="Print" />
<div id="div_print">
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="944px" ShowPrintButton="true" SizeToReportContent="True" AsyncRendering="false" ></rsweb:ReportViewer>
</div>
However, when I tried implementing this code, I encountered an error message stating 'Cannot read property 'innerHTML' of null'. What could be causing this issue?