Click here to Skip to main content
15,943,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Problem is to print crystal report using iFrame. In my following code I have called a Print() function in my server side code.

After clicking the button, it shows the error: Uncaught TypeError: Cannot read property 'contentWindow' of undefined(…)".

This Print() functions works perfectly for client side. How do I get solution now to call javascript function in my server side to print Crystal report?

What I have tried:

Server Side Code
protected void btnSave_Click(object sender, EventArgs e) {
  // any code here
  // load the database in crystal report
  // now I want to preview my print report with crystal viewer
  ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "Notification", "Print();", true);    

Client Side Code:
<div id="dvReport" class="col-md-12 col-sm-12 col-xs-12">
         <cr:crystalreportviewer id="CrystalReportViewer1" runat="server" width="600px" height="400px" autodatabind="true" bestfitpage="False" hastogglegrouptreebutton="False" hastoggleparameterpanelbutton="False" toolpanelview="None" enabledrilldown="False" printmode="Pdf">

        function Print() {
            var dvReceiptReport = document.getElementById("dvReport");
            var frame1 = dvReceiptReport.getElementsByTagName("iframe")[0];
                var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument;
j snooze 11-Nov-16 17:22pm    
clearly you are missing posting some code here because you have nothing named "iframe" in your html anywhere. Thus, when you try to getElementsByTagName("iframe") and set it to your frame1 object variable. Its null or nothing which means you can't access a property or method from a null or empty object.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900