Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET .NET Visual-Studio , +
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:
 
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:
 
protected void Page_Load(object sender, EventArgs e)
        {
 
                ReportViewer1.ServerReport.ReportPath = MyReportPathVariable;
                ReportViewer1.ServerReport.ReportServerUrl = new Uri(MyReportServerUrlVariable);
 
        }
Posted 2-Jul-13 8:40am
Comments
yloginov at 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));
 
}
johnaspnet at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
 
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);
 
}
  Permalink  
v3
Comments
johnaspnet at 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)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100