Solved

Cross browser printing

Posted on 2014-09-17
3
237 Views
Last Modified: 2014-09-18
Hi Experts,

I am attempting to following this post http://www.codicode.com/art/cross_browser_printing_with_asp_net_reportviewer.aspx on cross browser printing.  I keep getting an error when I run the debugger.  

JavaScript runtime error: '$' is undefined and highlighting this code

$('#printreport').click(function () {
    printReport('rv1');
});

I'm not very familiar with javascript.

// Print function (require the reportviewer client ID)
function printReport(report_ID) {
    var rv1 = $('#' + report_ID);
    var iDoc = rv1.parents('html');

    // Reading the report styles
    var styles = iDoc.find("head style[id$='ReportControl_styles']").html();
    if ((styles == undefined) || (styles == '')) {
        iDoc.find('head script').each(function () {
            var cnt = $(this).html();
            var p1 = cnt.indexOf('ReportStyles":"');
            if (p1 > 0) {
                p1 += 15;
                var p2 = cnt.indexOf('"', p1);
                styles = cnt.substr(p1, p2 - p1);
            }
        });
    }
    if (styles == '') { alert("Cannot generate styles, Displaying without styles.."); }
    styles = '<style type="text/css">' + styles + "</style>";

    // Reading the report html
    var table = rv1.find("div[id$='_oReportDiv']");
    if (table == undefined) {
        alert("Report source not found.");
        return;
    }

    // Generating a copy of the report in a new window
    var docType = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">';
    var docCnt = styles + table.parent().html();
    var docHead = '<head><title>Printing ...</title><style>body{margin:5;padding:0;}</style></head>';
    var winAttr = "location=yes, statusbar=no, directories=no, menubar=no, titlebar=no, toolbar=no, dependent=no, width=720, height=600, resizable=yes, screenX=200, screenY=200, personalbar=no, scrollbars=yes";;
    var newWin = window.open("", "_blank", winAttr);
    writeDoc = newWin.document;
    writeDoc.open();
    writeDoc.write(docType + '<html>' + docHead + '<body onload="window.print();">' + docCnt + '</body></html>');
    writeDoc.close();

    // The print event will fire as soon as the window loads
    newWin.focus();
    // uncomment to autoclose the preview window when printing is confirmed or canceled.
    // newWin.close();
};

Open in new window


@ Page Title="" Language="VB" MasterPageFile="../MasterPage.master" AutoEventWireup="false" CodeFile="ContributionReport.aspx.vb" Inherits="Accounting_ContributionReport" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

    <script type="text/javascript">
    // Linking the print function to the print button
$('#printreport').click(function () {
    printReport('rv1');
});
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main_container" Runat="Server">
    <h1>Contribution Report</h1>
    <asp:Button ID="Button1" runat="server" Text="Button" 
        onclientclick="printReport()" />    
    <table style="width: 100%;">
        </table>
    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
        Font-Size="8pt" Height="600px" ProcessingMode="Remote" Width="800px">
        <ServerReport ReportPath="/POSReports/ContributionReport" 
            ReportServerUrl="http://localhost:80/reportserver" />
    </rsweb:ReportViewer>
</asp:Content>

Open in new window

0
Comment
Question by:rcowen00
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40329352
You normally have to load jQuery before you use '$'.  One of the comments on that page says it doesn't work with a Master Page.
0
 

Author Comment

by:rcowen00
ID: 40329424
Ok, I will give it a try without the master page.
0
 

Author Comment

by:rcowen00
ID: 40330374
That did it. Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VS.net 2010 11 26
Access to class from any project within a solution. 6 14
Web Form VB.Net  import CSV 4 27
wordpress display sub menu only when click 12 24
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now