Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I have a 2012 asp.net web form application, and one of its asp.net web form page (named "ReportHolder.aspx") contains asp.net ReportViewer control whose Id on markup page is ReportViewer1. The ReportViewer control on ReportHolder.aspx page is used to get and show remote 2012 SQL Server Report Service rdl reports. Those rdl reports are created with parameter input fields that are populated from stored procedures.

I am looking for a way of how to pass a hidden parameter (named "WebLoginUserId") from report viewer control to reports in the code behind of "ReportHolder.aspx" on the first time loading of the "ReportHolder.aspx" page rather than using the "SubmittingParameterValues" event of report viewer that users must press the "View Report" button to pass such a hidden parameter to SSRS reports.


Currently, to pass such a hidden parameter from report viewer to remote rdl reports, I am using the "SubmittingParameterValues" event of the report viewer (see below). The problem with that event handler is users must press the "View Report" on reports so the hidden paramter "WebLoginUserId" value is passed.


My question: I would like to know if there is some way I can pass that hidden parameter to reports on the first time loading of the "ReportHolder.aspx" page rather than using the "SubmittingParameterValues" event of report viewer. Please help.


The "SubmittingParameterValues" event handler:

C#
protected void ReportViewer1_SubmittingParameterValues(object sender, ReportParametersEventArgs e)
        {
            if (e != null)
            {
                e.Parameters.Add(new ReportParameter("WebLoginUserId", someWebLoginUserVariable));
            }
        }


And the Page_Load event handler of "ReportHolder.aspx" who contains the report viewer control:

C#
protected void Page_Load(object sender, EventArgs e)
        {

                ReportViewer1.ServerReport.ReportPath = MyReportPathVariable;
                ReportViewer1.ServerReport.ReportServerUrl = new Uri(MyReportServerUrlVariable);

        }
Posted
Comments
Yuriy Loginov 2-Jul-13 15:13pm    
have you tried something like this? That is, put the code of your event handler inside page load.


protected void Page_Load(object sender, EventArgs e)
{

ReportViewer1.ServerReport.ReportPath = MyReportPathVariable;
ReportViewer1.ServerReport.ReportServerUrl = new Uri(MyReportServerUrlVariable);

....

e.Parameters.Add(new ReportParameter("WebLoginUserId", someWebLoginUserVariable));

}
Thomas Benz 2-Jul-13 16:05pm    
@yhloginov, thanks fro your reply. But the code line "e.Parameters.Add(new ReportParameter("WebLoginUserId", someWebLoginUserVariable));" does not work in the Page_Load event handler because e in there is EventArgs class while e in ReportViewer1_SubmittingParameterValues event handler is ReportParametersEventArgs class. So, I got a compile error.

Any ideas else?

1 solution

I think the key to achieving what you are after is loading the parameters on page load. You can try the code below.
Also this is the link has a discussion on this issue
http://social.msdn.microsoft.com/Forums/en-US/755c4bde-031d-431c-829d-000fe36f5a0b/how-to-programmatically-pass-parameters-to-a-reportviewer-i-c-net[^]
I would also recommend checking the Report Viewer API
http://msdn.microsoft.com/en-us/library/Microsoft.Reporting.WebForms.ReportViewer(v=vs.80).aspx[^]

C#
protected void Page_Load(object sender, EventArgs e)
{
    ReportViewer1.ServerReport.ReportPath = MyReportPathVariable;
    ReportViewer1.ServerReport.ReportServerUrl = new Uri(MyReportServerUrlVariable);

    List<ReportParameter> reportParams = new List<ReportParameter>();
    reportParams.Add(new ReportParameter("WebLoginUserId", someWebLoginUserVariable));

    ReportViewer1.LocalReport.SetParameters(reportParams);
    //or if you have a server report
    ReportViewer1.ServerReport.SetParameters(reportParams);

}
 
Share this answer
 
v3
Comments
Thomas Benz 18-Jul-13 14:55pm    
@yloginov, thank you.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900