Click here to Skip to main content
15,885,366 members
Articles / Web Development / ASP.NET

Print button and date picker in SSRS reports for non-IE browsers (Chrome, Firefox, etc.)

Rate me:
Please Sign up or sign in to vote.
4.94/5 (11 votes)
10 Dec 2012CPOL6 min read 209.5K   6.9K   24   18
This article will show you how to implement print functionality and the jQuery datepicker in non-IE browsers.

Introduction

SQL Server Reporting Services ReportViewer control has some limitations in non-IE browsers such as Chrome, Firefox, etc. Some of these limitations are:

  • Print button is not visible.
  • Date picker is not displayed as a date picker control.

This article will help you achieve the solution for the above limitations and design some complex reports.  

Background  

I have searched so many articles on the internet but could not find a better complete solution with the source code and I thought to share my experience with some of you experiencing the same issues in your reporting. I hope this article will help you and save some of your development time. 

I am very thankful to those techies who shared their experience along with the source on the web and helped me achieve this piece of work.  

Using the code 

Implementation of Print functionality

With this article we will achieve a solution to display a custom print button shown in the following figure on the Report Viewer toolbar:

Image 1

We will use the image control as a print button and the image control will be generated dynamically at runtime on the client side (please create your own GIF or JPEG image to show the image).

I know most of you will not agree with this approach but after a long research of more than a week I have come to a conclusion of implementing this functionality through AJAX calls to the server. This solution will create a temporary session PDF file and print the document at the client side and then delete the file on the server. Please follow these steps for the implementation (please make sure to have the user permissions on the server for creating/deleting the files).

Design of the ASPX page

  1. Place your ReportViewer control on the ASPX page:
  2. ASP.NET
    <rsweb:ReportViewer ID="rvREXReport" runat="server" Width="100%" Height="798px"
    Style="display: table !important; margin: 0px; overflow: auto !important;" 
    ShowBackButton="true" onreportrefresh="rrvREXReport_ReportRefresh">
    </rsweb:ReportViewer>   
  3. Place a server side iFrame below the ReportViewer:
  4. ASP.NET
    <iframe id="frmPrint" name="frmPrint" runat="server" style = "display:none"></iframe>
    
  5. Place the following div tag below the iframe declaration (this is to display the message while processing the AJAX request of printing):
  6. ASP.NET
    <div id="spinner" class="spinner" style="display:none;">
    <table align="center" valign="middle" style="height:100%;width:100%">
    <tr>
    <td><img id="img-spinner" src="../Images/ajax-loader.gif" alt="Printing"/></td>
    <td><span style="font-family:Verdana; font-weight:bold;font-size:10pt;width:86px;">Printing...</span></td>
    </tr>
    </table>
    </div>
  7. Place the ScriptManager:
  8. ASP.NET
    <asp:ScriptManager ID="ScriptManager1"  EnablePageMethods="true" 
        EnablePartialRendering="true" runat="server">
    </asp:ScriptManager>
  9. CSS classes are used to highlight the print button when the mouse is hovered on the print button (these CSS classes are available in the attached ASPX page).

Implementation of the client side script (jQuery/JavaScript)

To show the print button we will create a client side method that will generate the print and close buttons at runtime (please make sure to have the JPG/GIF images ready before you start the implementation). This method will be called on the body load event as well as report refresh event (at server side). Here is the explanation of how this has been implemented:

  1. We will have to find where the refresh button is available in the HTML code of the ReportViewer control.
  2. Once the refresh button is found from the above step, we will have to find the parent of the refresh button to add the image control.

Following is the method that will be used to create the print and close buttons:

JavaScript
function showPrintButton() {    
var table = $("table[title='Refresh']");
var parentTable = $(table).parents('table');
 ......remaining code here......

}

Tip: Install the developer tool on your machine to understand the HTML code which is generated on placing the ReportViewer control in the ASPX page.

Here we have two different client side methods which will be called before printing the report and after printing the report:

  1.  Before the printing method is used to send an AJAX request to the server, create a PDF at server and assign to the iframe at server side.
  2. JavaScript
    function ServerCallBeforePrint(btn) {
     $('#spinner').show();
     var context = new Object(); 
     ......remaining code here......
    }
  3. After printing method is used to send an AJAX request to the server, for deleting the PDF file which was created in the above step.
  4. JavaScript
    function ServerCallAfterPrint(btn) {
        var context = new Object();
        ......remaining code here......  
    
    }

    Tip: The attached ASPX page contains the full implementation of these methods.

Implementation of displaying jQuery datepicker

 Image 2

To implement this functionality, I have created a client side method which will be called on the document ready event. Following is the method used to display the jQuery datepicker:

JavaScript
function showDatePicker() {
   var parameterRow = $("#ParametersRowrvREXReport");
   ....remaining code here....
}

Please do not use exactly the same code as above because your parameter row ID might be different from the row ID in the above code. 

The following statements will explain how the parameter row ID is generated:

"ParametersRowrvREXReport" is the ID of the parameters row which can be identified from your HTML code generated by the ReportViewer control (as mentioned above, you would need to install the developer tool which is a freeware).

In the parameter row ID, the first part of the name is the common "ParametersRow (your ReportViewer name)" and the rest of the name is suffixed with your ReportViewer name. In the above example my ReportViewer name is "rvREXReport" which is why the name of the parameter row ID is generated as "ParametersRowrvREXReport".

And also, to find the date picker control (which is displayed as a texbox in Chrome/Firefox), I have used the label to find the table cell and from there I could identify the date control. Please note that we cannot rely on the name of the textbox as this will be generated at runtime and could be different. This is the reason I am using a label to find the date control on the report.

Tip: To use the above code, please make sure to use the date parameter in your report.

I have attached a sample project which contains the source with this article. Please note that this attachment will not contain the RDL file.

The attached project contains runnable files but will not contain support jQuery files (jquery-1.4.1.js, jquery-1.4.1.min.js, jquery-1.4.1-vsdoc.js) and the corresponding images. The attached project contains the proper structure to place all your files. I have tested this code properly in Google Chrome for my project and I hope this article will help you with all your needs to print the report in non-IE browsers and also display the jQuery datepicker control.  

Note: I have not included the SSRS report in the attached project. There are some configuration settings applied in the web.config file under the appSettings section. Please change those setting according to your needs. For your reference, I have attached a web.config file in the attached project.

What does the project contain?

  1. An ASPX page that implements the logic of displaying the print button and date picker control in the SSRS report viewer.
  2. ReportViewerCredentials.cs in the App_Code folder which is used to supply to the report the credentials to execute the report from the ASPX page.  
  3. A Web.config file which contains additional application settings in the appSettings section. 

Final Tips

  1. Keep the images under the "Images"  folder. Place your own "ajax-loader.gif" in this folder.
  2. Make sure all the default jQuery files (jquery-1.4.1.js, jquery-1.4.1.min.js, jquery-1.4.1-vsdoc.js) are under the scripts folder.
  3. Keep ReportViewerCredentials.cs under the App_Code folder of the project.
  4. Make sure to have permissions on the server to create and delete files.
  5. It is mandatory to have references to the following .NET libraries in the project:
    • Microsoft.Build.Framework
    • Microsoft.ReportViewer.Common
    • Microsoft.ReportViewer.WebForms
    • System.Management 

****If you like this article, please leave your comments/suggestions and rating.

History

If there are any further updates, they will be released in the next version.

License

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


Written By
Software Developer (Senior)
United Kingdom United Kingdom
Completed Masters in Computer Applications.

Comments and Discussions

 
QuestionThe resource cannot be found. Error Pin
phoohtoo17-Mar-16 23:47
phoohtoo17-Mar-16 23:47 
BugRe: The resource cannot be found. Error Pin
a.shokry6-Jun-16 0:29
a.shokry6-Jun-16 0:29 
QuestionThanks Much! Pin
Member 1193302816-Nov-15 21:58
Member 1193302816-Nov-15 21:58 
QuestionFunction ShowPrintButton Pin
patelv6113-Aug-15 14:43
professionalpatelv6113-Aug-15 14:43 
Question2014 Pin
Member 983785723-Apr-15 21:37
Member 983785723-Apr-15 21:37 
QuestionCalendar Postion is not correct Pin
NeelamSingh198621-Jan-15 18:20
NeelamSingh198621-Jan-15 18:20 
AnswerRe: Calendar Postion is not correct Pin
Shashidhar Rao Nellutla18-Mar-15 7:05
Shashidhar Rao Nellutla18-Mar-15 7:05 
GeneralGood Effort Pin
beshoynader15-Sep-14 23:12
beshoynader15-Sep-14 23:12 
QuestionTesting results (half fail) Pin
DevJuan11-Nov-13 1:57
DevJuan11-Nov-13 1:57 
QuestionClient side html print function Pin
Malek Chtiwi8-Oct-13 12:57
Malek Chtiwi8-Oct-13 12:57 
Questionit is giving the 404 error Pin
Member 381950920-May-13 2:51
Member 381950920-May-13 2:51 
PraiseRe: it is giving the 404 error Pin
phoohtoo18-Mar-16 0:04
phoohtoo18-Mar-16 0:04 
QuestionRDL Pin
bradmarsh28-Feb-13 11:50
bradmarsh28-Feb-13 11:50 
GeneralThank You Pin
Patrick Harris10-Dec-12 6:54
Patrick Harris10-Dec-12 6:54 
QuestionThis article is for server side reporting but what about client side reporting? Pin
Demo Test8-Dec-12 21:40
Demo Test8-Dec-12 21:40 
AnswerRe: This article is for server side reporting but what about client side reporting? Pin
Shashidhar Rao Nellutla9-Dec-12 23:07
Shashidhar Rao Nellutla9-Dec-12 23:07 
QuestionHow do I download the source code? Pin
Demo Test8-Dec-12 21:09
Demo Test8-Dec-12 21:09 
hi,
Thanks for the article.
But How do I download the source code?
AnswerRe: How do I download the source code? Pin
Shashidhar Rao Nellutla9-Dec-12 23:01
Shashidhar Rao Nellutla9-Dec-12 23:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.