0

I have ASP.NET Webforms which is using ReportViewer control to print reports (LocalReport) and, since direct printing is not working in Chrome and Firefox, i need to add button which will somehow do it in Chrome and Firefox. Any ideas?

aron
  • 1,874
  • 5
  • 23
  • 29

2 Answers2

0

I had the same issue once and found that explicitly specifying what controls in the ReportViewer control should be shown did the trick. I also added a ScriptManager to the page. The code below works in FireFox & Chrome. Also, the ReportViewer control has issues with other browsers when used in conjunction with UpdatePanels. Depending on how your markup is setup, these might be your issues.

    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"
        InteractiveDeviceInfos="(Collection)" ProcessingMode="Remote" WaitMessageFont-Names="Verdana"
        WaitMessageFont-Size="14pt" ShowExportControls="true" Width="1280px" Height="700px"
        ShowBackButton="true" ShowToolBar="true" ShowParameterPrompts="true" ShowPageNavigationControls="true"
        ZoomMode="Percent" ZoomPercent="100" ShowReportBody="true" InternalBorderStyle="Solid">
    </rsweb:ReportViewer>

Some issues such as ActiveX occur with older versions of the reporting controls. You can find out which version by looking in the web.config file. Version 8 and lower have this issue.

    <add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
    <add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />

Workarounds can be found here: ReportViewer Client Print Control “Unable to load client print control”?

Community
  • 1
  • 1
ShellNinja
  • 629
  • 8
  • 25
  • No, thats not the issue, issue is that Print button is only shown on Internet Explorer because this control apparently uses ActiveX. So how can we do the same thing without ActiveX? – aron Nov 19 '13 at 19:05
  • What version of .Net Framework and the Reporting controls are you using? Version 10 does not use ActiveX controls so it works in FireFox and Chrome. – ShellNinja Nov 22 '13 at 15:16
  • Just updated OA with the versions that are trouble prone and a workaround from stack. – ShellNinja Nov 22 '13 at 15:21
  • Your link to a workarounds mentions SQL Reporting but maybe i need to mention that im dealing with LocalReport? – aron Nov 22 '13 at 16:47
  • If it's a local report the link won't help upgrade your controls and it should still fix the issue. – ShellNinja Nov 25 '13 at 20:23
0

I've done it by the below js code: addPrintButton function added a print btn in the report viewer(ctl is the reportviewer's id. '#ctl00_cphMain_rvReportMain_ctl05' is the main div's id in reportviewr control, so you can change it according by the control client id):

function addPrintButton(ctl) {
var innerTbody = '<tbody><tr><td><input type="image" style="border-width: 0px; padding: 2px; height: 16px; width: 16px;" alt="Print" src="/App/Reserved.ReportViewerWebControl.axd?OpType=Resource&Version=10.0.40219.1&Name=Microsoft.Reporting.WebForms.Icons.Print.gif" title="Print"></td></tr></tbody>';
var innerTable = '<table title="Print" onclick="javascript:PrintFunc(\'' + ctl + '\'); return false;" id="do_print" style="cursor: default;">' + innerTbody + '</table>'
var outerDiv = '<div style="display: inline-block; font-size: 8pt; height: 30px;" class=" "><table cellspacing="0" cellpadding="0" style="display: inline;"><tbody><tr><td height="28px">' + innerTable + '</td></tr></tbody></table></div>';
$("#ctl00_cphMain_rvReportMain_ctl05 > div").append(outerDiv);}

and

function PrintFunc() {
var strFrameName = ("printer-" + (new Date()).getTime());
var jFrame = $("<iframe name='" + strFrameName + "'>");
jFrame
.css("width", "1px")
.css("height", "1px")
.css("left", "-2000px")
.css("position", "absolute")
.appendTo($("body:first"));

var objFrame = window.frames[strFrameName];
var objDoc = objFrame.document;
var jStyleDiv = $("<div>").append($("style").clone());
var styles = '<style type="text/css">' + jStyleDiv.html() + "</style>";
var docType = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
var docCnt = styles + $("#VisibleReportContentctl00_cphMain_rvReportMain_ctl09").html();
var docHead = '<head><title>...</title><style>body{margin:5;padding:0;}</style></head>';
objDoc.open();
objDoc.write(docType + '<html>' + docHead + '<body onload="window.print();">' + docCnt + '</body></html>');
objDoc.close();

}

SeeSharp
  • 608
  • 1
  • 13
  • 21