Search code examples
c#report-viewer2010

Flushing newest parameters from ReportViewer control to the ServerReport from code


After a user edits report parameters, at some point I try to access new parameters with

_reportViewer.ServerReport.GetParameters()

Since that gives only the parameters user has submitted to the server with click on the View Report button, I'm looking to:

a) Simulate click on a View Button from code or

b) Get those parameters in some other way, preferably one that doesn't involve reflection.

How could I "flush" the current parameters from the automatically generated report control from code?


Solution

  • If you call ReportViewer1.ServerReport.GetParameters() from the ReportViewer1 UnLoad event you will get the values the client entered.

    ASP.NET:

    <rsweb:ReportViewer ID="ReportViewer1" 
                                runat="server" 
                                ProcessingMode="Remote" 
                                AsyncRendering="true" 
                                EnableViewState="true" 
                                OnUnload="ReportViewer1_Unload">
    

    Codebehind:

        protected void ReportViewer1_Unload(object sender, EventArgs e)
        {
            ReportParameterInfoCollection ParameterCollection = ReportViewer1.ServerReport.GetParameters();
        }