BACKGROUND

ActiveReports WebViewer provides user with an option to view reports over the web in different formats. The viewer types available are RawHTML, HTML, PDF and FlashViewer. However the only viewer type among these which supports passing Parameters is HTML viewer. However the HTML viewer is not 100% WYSIWYG and has other limitations like a missing Print button. If we change the viewer type dynamically then the parameter values are not retained and the report is rendered again in its original form. So in this blog article we will see how we can switch from HTML viewer to PDF viewer type, retaining the passed parameter value. Also it it important to note that this approach is application to a Section Based Report. To do this, we will take little help of jQuery and rest all will be done using server side code. Here is a glimpse of what we are looking to achieve. Switching From HTML to PDF Viewer Type Switching From HTML to PDF Viewer Type

IMPLEMENTATION

So first of all, we will focus on getting the value entered into the parameter box. To do this, we will access the parameter box class using jQuery. Next we will get the text entered into it and store this value in a hidden field. The reason for doing this is to pass this value to the server side. This is the code we would use:

$(document).ready(function () {  
   $(".viewReportButton").click(function () {  
      $("#HiddenField1").val($(".parameterTextBox").val());  
   });  
});

Once we obtain the parameter value, it's time to focus on the server side code. Here we will first store the connection string and the SQL for the report in a session. Next we will get the value of the parameter from the hidden field and update the SQL string using it. Finally we will pass it to the report and show the report in a different viewer type. This is how our server side code looks:

rptParam report;  
protected void Page_Load(object sender, EventArgs e)  
{  
   if (!IsPostBack)  
   {  
      report = new rptParam();  
      WebViewer1.Report = report;  
      Session["connString"] = ((OleDBDataSource)report.DataSource).ConnectionString;  
      Session["SQL"] = ((OleDBDataSource)report.DataSource).SQL;  
   }  
}  

protected void btnToggle_Click(object sender, EventArgs e)  
{  
   string paramValue = HiddenField1.Value.ToString();  
   report = new rptParam();  
   OleDBDataSource ole = new OleDBDataSource();  
   ole.ConnectionString = Session["connString"].ToString();  
   string sqlString = Session["SQL"].ToString().Replace("<%param:parameter1%>", paramValue);  
   ole.SQL = sqlString;  
   report.DataSource = ole;  
   WebViewer1.ViewerType = GrapeCity.ActiveReports.Web.ViewerType.AcrobatReader;  
   WebViewer1.Report = report;  
}

So we are done. Add this code to your ASPX page and see the results. A sample application which demonstrates this implementation can be downloaded from the link below. Download C# Sample