title: Issue when trying to show/hide parameters in ASP.NET ReportViewer control
body: <p>I have an SSRS report that is displayed to users in the ASP.NET ReportViewer control. The report has many parameters and we're using the parameter prompts that the ReportViewer control offers. Depending on a certain parameter of the report, we only need to have the user prompted for a subset of the rest of the report parameters.</p>
  
  <p>We could have used linked reports and hide the appropriate parameters, but there are many possible combinations to that first parameter (it's multi-valued), so we'd rather not do that. Instead, we have an ASP.NET ListBox that controls the first parameter and when it's selection is changed, we are using the ReportViewer.ServerReport.SetParameters() function to hide/show parameters (it takes in an array of ReportParameter and the ReportParameter constructor takes in a boolean to hide/show the parameter).</p>
  
  <p>Here's the issue. Everything works fine in our development environment. When we deploy the report and the ASP.NET site to the production environment, parameters never get shown when those SetParameters() calls are invoked. We know the code is called because we put some debugging output to make sure. The code to hide parameters is working fine. It's just the code that should cause certain parameters to show up again doesn't work. Not only does it not show up the parameter prompts, but the Visible property of the parameter does not get set to true (checked by using ReportViewer.ServerReport.GetParameters()).</p>
  
  <p>We have SQL Server 2005 SP3 installed in both environments, and the same version of the report viewer control (Microsoft.ReportViewer.WebForms.dll). Any ideas what could be wrong? Any workaround ideas? If you have questions, leave comments.</p>
  
  <p><strong>Edit:</strong> After further investigation, we isolated the problem further. I made a simple report with just 1 parameter without any DB connection. Then I made an aspx page with 2 buttons and a ReportViewer control hooked up to that report. 1 button hides the parameter and 1 button shows the parameter (using the SetParameters() function, as mentioned above). Even with this simple scenario, the hide/show buttons work fine in the development environment, but we still have the same issue in the production environment (the show button doesn't work). We also tried this on another server on the network in the production environment, and we have the same issue. So everything seems to work fine in the development environment, but on 2 different servers outside that environment we seem to be getting the same issue.</p>
  
  <p><strong>Edit2:</strong> Below is the code behind for the test report page. The page has a ReportViewer, 2 Buttons, and a Label for debug output. When the showing of hidden parameters doesn't work, the Label even shows that the Visible property is still false after the call to ShowParameter.</p>
  
  <pre><code>Public Partial Class TestReportPage
      Inherits System.Web.UI.Page
  
      Public Sub HideParameter(ByVal parameterName As String)
          Dim parameters As ReportParameterInfoCollection = ReportViewer1.ServerReport.GetParameters()
          ReportViewer1.ServerReport.SetParameters(New ReportParameter() {New ReportParameter(parameterName, GetParameterDefaults(parameterName, parameters), False)})
          parameters = ReportViewer1.ServerReport.GetParameters()
          lblTest.Text &amp;= "Hide param " &amp; parameterName &amp; "; Is Visible: " &amp; parameters(parameterName).Visible &amp; "&lt;br&gt;"
      End Sub
      Public Sub ShowParameter(ByVal parameterName As String)
          Dim parameters As ReportParameterInfoCollection = ReportViewer1.ServerReport.GetParameters()
          ReportViewer1.ServerReport.SetParameters(New ReportParameter() {New ReportParameter(parameterName, GetParameterDefaults(parameterName, parameters), True)})
          parameters = ReportViewer1.ServerReport.GetParameters()
          lblTest.Text &amp;= "Show param " &amp; parameterName &amp; "; Is Visible: " &amp; parameters(parameterName).Visible &amp; "&lt;br&gt;"
      End Sub
      Public Shared Function GetParameterDefaults(ByVal parameterName As String, ByVal parameters As Microsoft.Reporting.WebForms.ReportParameterInfoCollection) As String()
          Dim paramDefaults() As String = {}
          Dim i As Int16 = 0
          For Each paramValue As String In parameters(parameterName).Values
              ReDim Preserve paramDefaults(i)
              paramDefaults(i) = paramValue
              i = i + 1
          Next
          Return paramDefaults
      End Function
      Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          HideParameter("foo")
      End Sub
      Protected Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
          ShowParameter("foo")
      End Sub
  End Class
  </code></pre>