开发者

Crystal report hangs on drill down after print

In my ASP.NET app using the crystal report viewer (ver 13.0.2000.0), when the user clicks "Print" and then either prints or cancels out of printing开发者_JS百科, when they next Drill Down in the report it will hang forever with the crystal dialog "Please wait while the document is being processed" with spinning triangle circle animation.

It does this in IE and Firefox, but it does NOT do this in Chrome: Instead the print button launches the PDF export with the "The viewer must export to PDF to print." messaging. This is what older versions of crystal did.

Right now I'm going down the road of forcing IE and Firefox to do the same thing as chrome - but if there's a real solution to the print problem - I'd rather use that. It seems when a user clicks Print (vs. export) they want to print (vs. export).


I came up with a work around for this. Since Crystal Reports does not allow overriding the buttons I ended up hiding the print button and adding my own print button using JavaScript/jQuery.

Here is some under-the-hood info on how the printing works. When you press the print button it does a postback with the view states and event arguments. The post back returns a PDF file which the browser opens inline. The PDF file is embedded with a print command which is executed when the file is opened.

So what we can do is use a hidden IFRAME to load the printable PDF. This way the main page is not affected. I think the PDF loading inline is what causes the page/browser to corrupt its state.

Place the below code at the top of your ASPX page. You must place it at the top of the page otherwise the print dialog will be off the screen if you put it at the bottom.

Here is the HTML:

<iframe id="HiddenFrame" name="HiddenFrame" style="display: none;"></iframe>
<form id="PrintForm" action="MyPage.aspx" method="post" target="HiddenFrame">
    <!-- Change the name if your object is not named 'CrystalReportViewer1' -->
    <input type="hidden" name="__CRYSTALSTATECrystalReportViewer1" id="CRState" />
    <input type="hidden" name="__VIEWSTATE" id="VState" />
    <!-- Change this value to match your CrystalReportViewer object's name. -->
    <input type="hidden" name="__EVENTTARGET" value="CrystalReportViewer1" />
    <!-- This is the print command that is sent. -->
    <input type="hidden" name="__EVENTARGUMENT" value='{"text":"PDF", "range":"false", "tb":"crpdfprint"}' />
</form>

As mentioned above, the IFRAME will load our PDF. The form is used to do a POST to the server with the view states and event arguments. The target attribute tells the form to load in the IFRAME.

Here is the JavaScript:

// Hide the print button.
$('#CrystalReportViewer1_toptoolbar_print').hide();
// Inject our own print button. You can apply the same icon to your print button using CSS to make it look like the original icon.
$('#CrystalReportViewer1_toptoolbar_print').parent().append('<div id="PrintButtonOverride"></div>');

// When user clicks our print button, copy the states and submit the form.
$('#PrintButtonOverride').click(function () {
    $('#CRState').val($('#__CRYSTALSTATECrystalReportViewer1').val());
    $('#VState').val($('#__VIEWSTATE').val());
    $('#PrintForm').submit();
});

The click event copies the two view states from the main page and then submits the form. I wrote this post quickly so I apologize if I left something unclear.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜