Handling report hyperlinks in Wijmo ReportViewer

When the report, rendered in Wijmo ReportViewer, contains hyperlinks by setting the LinkTarget property of the report field and the links are clicked, they open in the same browser window. This is the default behavior of hyperlinks in the ReportViewer control. But, sometimes, we have a requirement to open these links in a new window. In this blog, we will see how we can achieve the same. In order to override the default behavior, we need to write custom script for the hyperlinks included in our report. These hyperlinks can be created explicitly and can be added in the body of the report’s document. Here is the code which can be used:

RenderText rt2 = new RenderText("execute custom script.");  
rt2.Hyperlink = new C1Hyperlink(new C1LinkTargetFile("javascript:openPage('http://google.com/')"));  

Note that in the above code, we have used a method called “openPage” which is defined in javascript as follows:

<script type="text/javascript">  
 function openPage(url){  
 window.open(url, "mywindow");  

This method tells the C1ReportViewer that the target should open in a new browser window. Instead of creating new hyperlink, we can also directly set the LinkTarget property to the desired link with the help of below code:

 protected C1PrintDocument MakeDoc()  
    C1PrintDocument doc = new C1PrintDocument();  
    C1Report report = C1ReportViewer.CreateC1Report();  

    report.Load(Server.MapPath("~/XML/CommonTasks.xml"), "01: Alternating Background (Greenbar report)");  

    report.Sections["Detail"].Fields["QuantityPerUnitCtl"].LinkTarget = "javascript:openPage('http://google.com/')";  
    doc = report.C1Document;  
    return doc;  


GrapeCity Developer Tools
comments powered by Disqus