I have used the code used in my article Create Crystal Report using Stored Procedure in ASP.Net with C# and VB.Net
HTML
I have placed the Crystal Report in an HTML DIV.
<div id = "dvReport">
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true"
Height="400" Width="600" BestFitPage="False" />
</div>
<br />
<asp:Button ID="btnPrint" Text="Print" runat="server" OnClientClick = "return Print()" />
JavaScript
In JavaScript the following funciton is executed which prints the Crystal Report.
<script type="text/javascript">
function Print() {
var dvReport = document.getElementById("dvReport");
var frame1 = dvReport.getElementsByTagName("iframe")[0];
if (navigator.appName.indexOf("Internet Explorer") != -1) {
frame1.name = frame1.id;
window.frames[frame1.id].focus();
window.frames[frame1.id].print();
}
else {
var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument;
frameDoc.print();
}
}
</script>