Asked by:
Getting ReportViewer client parameters at runtime

Question
-
User-599019322 posted
I cannot seem to do the following:
1) I have a report that uses the ASP.NET 2.0 Report Viewer against a RS2005 report that has parameters. Some have default values. One is a text box. Others are drop-down lists.
2) I have ShowParameterPrompts = true and am presented the parameter area upon first visit to the page.
3) I fill in the parameters on the web browser page and click the View Report button
4) Now, on the server side, I want to examine the parameter values (in the Page_Load event). When I do a GetParameters on the ServerReport of the ReportViewer, I receive back a collection of the default parameters values, not the values that I just submitted.How do I see the parameter values submitted by the client?
Other information I found while investigating this:
1) If I click on the View Report button again (and again), GetParameters always return the previous set of parameters, not the current values that the client submitted.
2) If I look at the Request.Forms collections I can see values for controls that have been generated by the ReportViewer control in the parameters area - where the values are different when the client submitts new parameters.
3) If I do a GetParameters in the pages Page_PreRender event, I see the same behavior.
4) I can do a walk of the control tree inside the report view control instance and see the various controls created for the parameters area. Those controls have the Request.Form values in them.
5) The Report Viewer, load, report refresh and prerender events don't seem to be much help either.I could hack a solution using the control tree or the Request.Form values, but that's rather inelegant and relies on Micrsoft not changing the ReportViewer control's behavior.
Any explanations of what is happening here would be appreciated. Thanks,
ER Doll
Wednesday, December 27, 2006 1:19 PM
All replies
-
User-1583903539 posted
I am having a similar problem. Have you found a solution, specifically to number 1 in the second section of your message?
CWaitz
Monday, April 2, 2007 5:52 PM -
User156843398 posted
I am also trying to find how to get the parameters that the user has set when they hit the View Report button. But I think this is what happens when you do a GetParameters when you hit the View Report button on the ReportViewer control:
When you do a GetParameters() it gets the values of the parameters of the report that is already generated on the screen. So if you were to change the parameters and click View Report, in your Page_Load when you call GetParameters(), this is looking at the parameters before your new report is generated. So if you wanted the new parameters that the user has inputted, you would need to wait for the report to get generated then do a postback and use GetParameters.
If anyone knows how to get the parameter values the user has selected before the report is generated, please let us know.[:^)]
Tuesday, May 15, 2007 3:52 PM -
User1485238302 posted
Examine your parameters in isPostBack block.
protected void Page_Load(object sender, EventArgs e) { if(isPostBack) { //EXAMINE } }
Tuesday, May 15, 2007 3:55 PM -
User156843398 posted
Examine your parameters in isPostBack block.
protected void Page_Load(object sender, EventArgs e) { if(isPostBack) { //EXAMINE } }
I've been doing this but it doesn't work. If it were a DateTime parameter then it would work because when you change the date in ReportViewer it does a Postback which updates the ReportViewer. Is it possible to always do a Postback whenever a value for a parameter is changed? Even for String parameters that appear as textboxes? This would solve my problem.
Tuesday, May 15, 2007 4:15 PM -
User1485238302 posted
What about using TextChanged and SelectedIndex changed event. Make a function where you load your Reportviewer. Call that function everytime there is text changed or selected index changed.
Tuesday, May 15, 2007 4:22 PM -
User156843398 posted
I don't have access to those events since the controls are rendered automatically in the ReportViewer depending on what type of parameter it is. I'm trying to see if there is a property in the actual parameter creation when creating the report. There has to be because one of my reports that has a dropdown list did a postback whenever the selection changed. But another report didn't. I have to find out how this happened...Tuesday, May 15, 2007 4:36 PM -
User-999734230 posted
The values of the parameters are stored in the view state of the parameter controls. Unfortunately, as you mentioned, you don't have direct access to those controls at run time. However, you do have access to them through the Controls collection of the ReportViewer, if you know what to look for. The following code will extract the currently selected parameter values. NOTE: this code uses reflection and is dependent on the internal implementation of the parameter controls. This is necessary since the ReportViewer does not expose the values of these controls in any other way.
Public Function GetCurrentParameters(ByVal viewer As Microsoft.Reporting.WebForms.ReportViewer) As ReportParameter() Dim paramsArea As Control = FindParametersArea(viewer) Dim params As New List(Of ReportParameter)() FindParameters(paramsArea, params) Return params.ToArray() End Function Private Function FindParametersArea(ByVal viewer As Microsoft.Reporting.WebForms.ReportViewer) As Control For Each child As Control In viewer.Controls If child.GetType().Name = "ParametersArea" Then Return child End If Next Return Nothing End Function Private _ParameterControlType As Type = System.Reflection.Assembly.GetAssembly(GetType(Microsoft.Reporting.WebForms.ReportViewer)).GetType("Microsoft.Reporting.WebForms.ParameterControl") Private Sub FindParameters(ByVal parent As Control, ByVal params As List(Of ReportParameter)) Dim param As ReportParameter Dim paramInfo As ReportParameterInfo Dim paramValues As String() For Each child As Control In parent.Controls If _ParameterControlType.IsAssignableFrom(child.GetType()) Then paramInfo = CType(GetPropertyValue(child, "ReportParameter"), ReportParameterInfo) If paramInfo Is Nothing Then Continue For paramValues = CType(GetPropertyValue(child, "CurrentValue"), String()) If Not paramValues Is Nothing AndAlso paramValues.Length > 0 Then param = New ReportParameter() param.Name = paramInfo.Name param.Values.AddRange(paramValues) params.Add(param) End If End If FindParameters(child, params) Next End Sub Public Function GetPropertyValue(ByVal target As Object, ByVal propertyName As String) As Object Return target.GetType().GetProperty(propertyName, BindingFlags.IgnoreCase Or BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public).GetValue(target, Nothing) End Function
Wednesday, June 13, 2007 11:08 AM -
Wednesday, November 21, 2007 1:03 PM
-
User-397940054 posted
Hi,
my problem is some thing similar. i have a database which stores data belonging to multiple clients. what i have to do is i have to apply the client ID while showing data in areport. i am using reportviewer for this purpose. i can pass the value for client id only if i add the clientid parameter to prompt. then there is every chance of user changing the value as it will be visible on the reportviewer along with other parameters. so i want to set the appropriate value for this parameter before passing it to the report. i think the code that you have given will work for me.can you please send the equivalent C# code.
Thanks in advance.
Srik
Wednesday, April 9, 2008 2:27 AM -
User-397940054 posted
ok. i got the C# code. but my requiremnt is to set the value for the parameter. how can i do this?
thanks, srik
Thursday, April 10, 2008 6:17 AM -
User-1247908627 posted
Hi!
Thanks for the code! I have implemented it in my project however I am having a problem calling the method GetPropertyValue(..) I don't know what 'target' is. I understand the propertyName will be the property name from my report, I just don't know what I need to pass in as target.
Thanks!
John
Wednesday, April 16, 2008 10:55 AM -
User-858508668 posted
This code looks like just the ticket, but my site is all in C#. I noticed that you have sent a C# version to one respondent. Could you please send it to me as well? The email address is larry.whipple@gmail.com.
Thanks!
Larry
Wednesday, June 18, 2008 12:39 PM -
User-858508668 posted
John,
Can you send me the C# code you received? I'm dealing with almost the same issue and converting this from the VB that was posted is problematic.
Thanks!
Larry
Wednesday, June 18, 2008 12:40 PM -
User-1247908627 posted
I dind't get a c# version, I was refering to the posted code.
Wednesday, June 18, 2008 2:01 PM -
User-858508668 posted
Hmmm... Okay. Thanks for the reply. I'm hoping someone out there has it in C#. It appears that there are a couple of differences in the v9 version of ReportViewer that are giving me headaches. For example, there doesn't appear to be a ParameterControl object in the WebForms anymore and I'm also having some difficulties in the GetPropertyValue method with an "object reference not set to an instance of an object." If you have c# experience I'd be more than happy to have you look at the code and let me know what you see. Here's what I have for both those:
public Type _ParameterControlType;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>_ParameterControlType = Assembly.GetAssembly(this.EdgeReportViewer.GetType()).GetType("Microsoft.Reporting.WebForms.ReportParameter");
The above at least compiles, but I don't think it's getting the same type reference since I'm looking at ReportParameter and not ParameterControl (which seems to have disappeared from the WebForms object).
This is what it looks like using most of the same code from the example (the change is to the reportviewer instance rather than the class itself)
<o:p></o:p> //_ParameterControlType = Assembly.GetAssembly(this.EdgeReportViewer.GetType()).GetType("Microsoft.Reporting.WebForms.ParameterControl");<o:p></o:p>The method that's problematic is:<o:p></o:p>public Object GetPropertyValue(Object target, String propertyName)
<o:p></o:p>{<o:p></o:p>return target.GetType().GetProperty(propertyName, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(target, null);<o:p></o:p>}<o:p></o:p>It generates the error when evaluating the Instance BindingFlag.
Any suggestions would be greatfully accepted. As with most projects, this is a “yesterday” kind of deadline.
Thanks for any help!
<o:p> </o:p>Larry
Wednesday, June 18, 2008 5:16 PM -
User-1247908627 posted
I wish I could be of more help but I had the same problem with the same method. I wasn't able to get anywhere with it. Perhaps someone out there with a bit more experience with the report viewer and c# may be able to help. You were atleast able to get it to compile, I was not.
I beleive there are some short comings of the report viewer, or it could just be my inexperience with it. I have alot more to learn about it.
Wednesday, June 18, 2008 5:58 PM -
User-858508668 posted
okay - thanks. I completed the conversion and it seems to be working okay although I never could get the Type to work properly so just ended up handling it another way. If anyone would like the code, I'll put it at the end.
I do have one more issue though - the SetParameters doesn't seem to be actually setting the parameters for the report. I'm doing it in the PreRender event handler. I don't think that should be a problem, but when I set the parameters it seems to ignore them, so I'm off on a hunt for that now. Any suggestions would be gratefully appreciated.
Here's the C# version of the code:
public List<ReportParameter> GetClientParameters(ReportViewer viewer){
Control paramsArea = FindParametersArea(viewer); List<ReportParameter> thisParams = new List<ReportParameter>();FindParameters(paramsArea, thisParams);
return thisParams;}
private Control FindParametersArea(ReportViewer viewer){
foreach (Control child in viewer.Controls){
if (child.GetType().Name == "ParametersArea") return child;}
return null;}
private List<ReportParameter> FindParameters(Control parent, List<ReportParameter> thisParams){
ReportParameter param; ReportParameterInfo paramInfo; String[] paramValues; foreach( Control child in parent.Controls){
//if ( _ParameterControlType.IsAssignableFrom(child.GetType() ) ) - THIS IS THE PART i COULDN'T GET TO WORK PROPERLY{
paramInfo = (ReportParameterInfo)GetPropertyValue(child, "ReportParameter"); if (paramInfo == null ) continue;paramValues = (
String[])GetPropertyValue(child, "CurrentValue"); if (paramValues != null && paramValues.Length > 0 ){
param = new ReportParameter();param.Name = paramInfo.Name;
param.Values.AddRange(paramValues);
thisParams.Add(param);
}
}
FindParameters(child, thisParams);
}
return thisParams;}
public Object GetPropertyValue(Object target, String propertyName){
object retVal = target.GetType().GetProperty(propertyName); if (retVal != null) retVal = target.GetType().GetProperty(propertyName).GetValue(target, null); return retVal;}
Friday, June 20, 2008 10:37 AM -
User1137074964 posted
I cannot seem to do the following:
1) I have a report that uses the ASP.NET 2.0 Report Viewer against a RS2005 report that has parameters. Some have default values. One is a text box. Others are drop-down lists.
2) I have ShowParameterPrompts = true and am presented the parameter area upon first visit to the page.
3) I fill in the parameters on the web browser page and click the View Report button
4) Now, on the server side, I want to examine the parameter values (in the Page_Load event). When I do a GetParameters on the ServerReport of the ReportViewer, I receive back a collection of the default parameters values, not the values that I just submitted.How do I see the parameter values submitted by the client?
Other information I found while investigating this:
1) If I click on the View Report button again (and again), GetParameters always return the previous set of parameters, not the current values that the client submitted.
2) If I look at the Request.Forms collections I can see values for controls that have been generated by the ReportViewer control in the parameters area - where the values are different when the client submitts new parameters.
3) If I do a GetParameters in the pages Page_PreRender event, I see the same behavior.
4) I can do a walk of the control tree inside the report view control instance and see the various controls created for the parameters area. Those controls have the Request.Form values in them.
5) The Report Viewer, load, report refresh and prerender events don't seem to be much help either.I could hack a solution using the control tree or the Request.Form values, but that's rather inelegant and relies on Micrsoft not changing the ReportViewer control's behavior.
Any explanations of what is happening here would be appreciated. Thanks,
ER Doll
Hi, I implemented more complex task with report parameters. I don't use ShowParameterPrompts = true. I will put some examples on my site soon.
Alexei Cioina.
http://www.californiadreamhomesandland.com
Monday, June 23, 2008 8:52 PM -
User-858508668 posted
Thanks for the help. I have it running very well right now. Here's what I had to do:
1 - I get the current defaults from the ServerReport using the GetParameters method. This returns the default parameters for the ServerReport
2 - I have some parameter limits and defaults for my application that I need to apply to various report parameters. We're storing these in a local SQL Server database using the reportpath to uniquely identify the report. I put those in generic List of Report Parameters.
3 - I also walk the control tree and extract everything in there that looks like a report parameter into a generic List of ReportParameter (these are what my user modified)
Finally, I use a method to come up with a "final" set of parameters to use for this render and then apply those to the ServerReport using SetParameters(). The method takes the default parameters and then adjusts values based on the parameter limits and defaults and then applies the client parameters last. I use the PromptUser and Visibility attributes to determine if I should even bother with the client-manipulated parameter. At the bottom of the method I simply apply the resulting List using SetParameters.
I do all of this in the PreRenderEventHandler. The reflection through the control tree (see my c# code above) is not overly costly, although there is an impact. Still, the whole thing works great now. I'm also storing that collection of parameters and other information about the ServerReport into a Report object that I create and store in a stack so I can allow my user to step back and forward through the reports they've rendered and have them show up using the parameters they specified originally. I've even created my own breadcrumb trail so I can show drilldowns, etc.
Thanks for the help everyone!
Now on the the next thing - disabling the contextmenu for the Reserved.ReportViewer. I can get the rest of the screen to ignore righ-clicks, but the ReportViewer frame doesn't seem to want to allow me to disable that. Even a walk through the frames collection doesn't seem to be getting the results I want - GRRRR!!!!
Tuesday, June 24, 2008 11:59 AM -
User1137074964 posted
It is very interesting code. I use another way.
Alexei Cioina.
Tuesday, June 24, 2008 12:26 PM -
User-858508668 posted
Thanks,
The code for getting the parameter prompt values works great. I'm still dealing with two items though and was wondering if anyone who has followed this thread has any ideas of how to do these things:
1 - I need to occasionally set the Client parameter values. The Control object collection appears to be read-only so I'm not clear how I can write to it. Any suggestions? I've walked the code that I use to get to it using the GetClientParameters code and can see it clearly and even had a plan for how to replace the value, but without being able to write to it couldn't get any further. I can simply allow the parameter bar values to be disconnected from the report until the "view report" button is selected, but that is a less desirable effect. Suggestions?
2 - I need to disable the contextmenu in the reportviewer area. I can easily disable it in the page, but the reportviewer uses iframes. I've tried walking the frame collection and even specifying the frame directly, but the context menu still appears on a right-click. From what I can tell it appears that the ReportViewer is doing something with it in its .js, but since my onload in the body runs last I had hoped and assumed it would overwrite that setting - no such luck. Suggestions?
Thanks again for the help.
Larry
Wednesday, June 25, 2008 6:16 PM -
User754480199 posted
I have discovered the correct syntax and assemply reference to use for the line of code you and I and I am sure a lot of other people were having a problem to work correctly.
What it should be is the following:
Private _ParameterControlType As Type = System.Reflection.Assembly.GetAssembly(GetType(Microsoft.Reporting.WebForms.ReportViewer)).GetType("Microsoft.Reporting.WebForms.BaseParameterInputControl")This is the new ParameterControl that we have all been looking for. Put this in and everything works like expected. When you get the returned parameters from the GetCurrentParameters function just assign them to the report and it will update the report on the page dynamically.
If Page.IsPostBack ThenrptParms = GetCurrentParameters(rptViewer)
rptViewer.ServerReport.SetParameters(rptParms)
Now I have to ask a question and hopefully someone can help me out. I am trying to use the export to excel from the ReportViewer and the date fields that are on the report come as just a big number when it gets to excel and then causes excel to throw an error...Has anyone else had this issue and if so, how do I go about fixing it?
Thursday, October 9, 2008 12:52 PM -
User1265476689 posted
Hello ,
I am novice to ASP.net and need all your help in generating dynamic parameters for a selected report on a tree contol. I have developed a similar application using Winforms,SSRS, ReportingWebservice2005 and I had a no problem earlier. We have moved our application to Web and need to develop a similar application.
I have created a tree view conrol and was able to populate all the reports from the report server. Problem is generating the parameters for the selected report. Please help me completing this task with some code examples.
Please help me.
--Deepak
Thursday, October 9, 2008 3:05 PM -
User754480199 posted
The first question that I have for you is are you trying to create the parameters at runtime or have they already been created as part of the report rdl file and you just need to populate them?
Thursday, October 9, 2008 3:10 PM -
User1265476689 posted
I have report parameters created for all the reports on report server. I need to create controls with their lables and datatype for the selected report on a seperate <TD> tag or user contol. In acheiving this first step, I need to get all the paramteres that are declared for the selected report. I am facing problem in getting the list of parameters.
Thanks for quick response.
Deepak
Thursday, October 9, 2008 3:31 PM -
User754480199 posted
There are two ways to go about this.
the first and easiest way is to simply set the ShowParameterPrompts property to true on the reportviewer control.
The second would be in the code behind and if you just want to know what the parameters are and set them you could use
rptViewer.ServerReport.GetParameters()
Thursday, October 9, 2008 3:42 PM -
User1265476689 posted
I am using ReportingService2005 webservice to get all the list of reports from reportserver and displaying them on RadTreeView Cotrol. On one of the tree Node I am clicking a report and would like to know what are the parameters that are associated with that report and after getting the list of parameters , I need to get their DataType and create dynamic controls (lable, textbox,dropdown). After the user enters their parameter values, then I need to validate these parameter values against the report parameter values and then display the generated report on a report viewer contol.
Displaying the report is the final part ,untill then I have get all the parameters using WebService only.
Hope I explained it clearly....let me know if you need more info.
--Deepak
Thursday, October 9, 2008 3:52 PM -
User754480199 posted
The best way for you to get all of the information you need is add the web reference to the reporting service to your application and then look at the Reference.vb file that is created for you under the WebReference folder. I'm not exactly sure what you are trying to accomplish but that file has all of the SOAP calls that can be made to the web service and I am sure you will find what you need.
Sorry I couldn't be more help but I don't have the time right now to create the code for your project as I have my own projects to attend to.
If you still have issues after you look into the web service file then let me know and I will try to help you some more.
Thursday, October 9, 2008 4:08 PM -
User1265476689 posted
Hello All,
After getting all the parameters for a selected report, how do I generate controls based on Datatype and display them on the asp.net page. Any help would be highly appriciated.
Deepak
Monday, October 13, 2008 9:43 AM -
User-922747591 posted
After hours of trying, this works, the whole source code :) enjoy!
Imports System.IO
Imports System.Net
Imports System.Web
Imports Microsoft.Reporting.WebForms
Imports Microsoft.Reporting
Imports Microsoft.ReportingServices
Imports MyReportServerCredentials
Imports System.Reflection
Public Class _Default
Inherits System.Web.UI.Page
Dim ReportPath As String = String.Empty
Dim ReportServerUrl As String = "String.Empty"
Dim dealerID As Integer = "0"
Dim _user As String = String.Empty
Dim _password As String = String.Empty
Dim _languagecode As String = String.Empty
Dim rsFormat As String = String.Empty
Dim rstoolbar As Boolean
Dim rsdocmap As Boolean
'' this is for postback to remember the parms
Dim PostParms As New Dictionary(Of String, String)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
GetCurrentParameters(ReportViewer1) '' ReportViewer1 is the UserConrtol on the aspx page
End If
Call querystrings()
End Sub
Protected Sub ReportViewer1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles ReportViewer1.Load
ReportViewer1.ShowCredentialPrompts = False
ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials()
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
ReportViewer1.ServerReport.ReportServerUrl = New System.Uri(ReportServerUrl)
ReportViewer1.ServerReport.ReportPath = ReportPath
ReportViewer1.ShowPrintButton = True
ReportViewer1.ShowToolBar = rstoolbar
ReportViewer1.ShowDocumentMapButton = rsdocmap
ReportViewer1.EnableViewState = True
ReportViewer1.ShowParameterPrompts = True '' hide and show the date from
ReportViewer1.ShowPromptAreaButton = True
ReportViewer1.ShowCredentialPrompts = False
ReportViewer1.ShowFindControls = True
ReportViewer1.ShowPageNavigationControls = False
ReportViewer1.ShowToolBar = True
Dim paramList As New Generic.List(Of ReportParameter)
paramList.Add(New ReportParameter("DealerID", dealerID))
paramList.Add(New ReportParameter("Password", _password))
paramList.Add(New ReportParameter("UserName", _user))
If Page.IsPostBack Then '' only send the datas afterpostback because we will use the default values to start with
Dim pair As KeyValuePair(Of String, String)
For Each pair In PostParms
paramList.Add(New ReportParameter(pair.Key, pair.Value))
Next
End If
ReportViewer1.ServerReport.SetParameters(paramList)
ReportViewer1.ServerReport.Refresh()
End Sub
Private Sub querystrings()
'' a whole bunch of querystrings, that you really do not need for thsi example, things like username, passwords, ect... from the calling page.
End Sub
'' Below is the code with a few changes i stole from the kind user from the first page. I just added in a cool Dictonary Key list.
#Region "PARMS"
Public Function GetCurrentParameters(ByVal viewer As Microsoft.Reporting.WebForms.ReportViewer) As ReportParameter()
Dim paramsArea As Control = FindParametersArea(viewer)
Dim params As New List(Of ReportParameter)()
FindParameters(paramsArea, params)
Return params.ToArray()
End Function
Private Function FindParametersArea(ByVal viewer As Microsoft.Reporting.WebForms.ReportViewer) As Control
For Each child As Control In viewer.Controls
If child.GetType().Name = "ParametersArea" Then
Return child
End If
Next
Return Nothing
End Function
Private _ParameterControlType As Type = System.Reflection.Assembly.GetAssembly(GetType(Microsoft.Reporting.WebForms.ReportViewer)).GetType("Microsoft.Reporting.WebForms.ParameterControl")
Private Sub FindParameters(ByVal parent As Control, ByVal params As List(Of ReportParameter))
Dim param As ReportParameter
Dim paramInfo As ReportParameterInfo
Dim paramValues As String()
For Each child As Control In parent.Controls
'' If _ParameterControlType.IsAssignableFrom(child.GetType()) Then HAD TO COMMET OUT BECAUSE IT DID NOT WORK, THIS IS WHY I ADDED A TRY DOWN BELOW
paramInfo = CType(GetPropertyValue(child, "ReportParameter"), ReportParameterInfo)
If paramInfo Is Nothing Then Continue For
paramValues = CType(GetPropertyValue(child, "CurrentValue"), String())
If Not paramValues Is Nothing AndAlso paramValues.Length > 0 Then
param = New ReportParameter()
param.Name = paramInfo.Name
param.Values.AddRange(paramValues)
params.Add(param)
''added this to make simple Dictonary KeyValue
PostParms.Add(paramInfo.Name.ToString(), param.Values.Item(0))
End If
'' End If
FindParameters(child, params)
Next
End Sub
Public Function GetPropertyValue(ByVal target As Object, ByVal propertyName As String) As Object
Try '' i added this
Return target.GetType().GetProperty(propertyName, BindingFlags.IgnoreCase Or BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public Or BindingFlags.GetField Or BindingFlags.Instance).GetValue(target, Nothing)
Catch
Return Nothing
End Try
End Function
#End Region
End ClassThursday, January 21, 2010 8:27 AM -
User-922747591 posted
Oh forgtt, for those who need to pass Parms for Username and Passwords that need to sent to the ReportServer , they are in the above post. You need to add one class as like below. But i think most people do not need the below.
Imports System.Net
Imports System.Security.Principal
Imports Microsoft.Reporting.WebForms<Serializable()> _
Public NotInheritable Class MyReportServerCredentials
Implements IReportServerCredentialsPublic ReadOnly Property ImpersonationUser() As WindowsIdentity Implements IReportServerCredentials.ImpersonationUser
Get
Return Nothing
End Get
End PropertyPublic ReadOnly Property NetworkCredentials() As ICredentials _
Implements IReportServerCredentials.NetworkCredentials
Get
Dim userName As String = ConfigurationManager.AppSettings("Credential_Username").ToString()If (String.IsNullOrEmpty(userName)) Then
Throw New Exception("Missing user name from web.config file")
End If
Dim password As String = ConfigurationManager.AppSettings("Credential_Password").ToString()If (String.IsNullOrEmpty(password)) Then
Throw New Exception("Missing password from web.config file")
End If
Dim domain As String = ConfigurationManager.AppSettings("Credential_url").ToString()If (String.IsNullOrEmpty(domain)) Then
Throw New Exception("Missing domain from web.config file")
End IfReturn New NetworkCredential(userName, password, domain)
End Get
End PropertyPublic Function GetFormsCredentials(ByRef authCookie As Cookie, ByRef userName As String, ByRef password As String, ByRef authority As String) As Boolean Implements IReportServerCredentials.GetFormsCredentials
authCookie = Nothing
userName = Nothing
password = Nothing
authority = "Ntlm"Return False
End Function
End Class
Thursday, January 21, 2010 8:33 AM -
User1137074964 posted
Oh forgtt, for those who need to pass Parms for Username and Passwords that need to sent to the ReportServer , they are in the above post. You need to add one class as like below. But i think most people do not need the below.
Imports System.Net
Imports System.Security.Principal
Imports Microsoft.Reporting.WebForms<Serializable()> _
Public NotInheritable Class MyReportServerCredentials
Implements IReportServerCredentialsPublic ReadOnly Property ImpersonationUser() As WindowsIdentity Implements IReportServerCredentials.ImpersonationUser
Get
Return Nothing
End Get
End PropertyPublic ReadOnly Property NetworkCredentials() As ICredentials _
Implements IReportServerCredentials.NetworkCredentials
Get
Dim userName As String = ConfigurationManager.AppSettings("Credential_Username").ToString()If (String.IsNullOrEmpty(userName)) Then
Throw New Exception("Missing user name from web.config file")
End If
Dim password As String = ConfigurationManager.AppSettings("Credential_Password").ToString()If (String.IsNullOrEmpty(password)) Then
Throw New Exception("Missing password from web.config file")
End If
Dim domain As String = ConfigurationManager.AppSettings("Credential_url").ToString()If (String.IsNullOrEmpty(domain)) Then
Throw New Exception("Missing domain from web.config file")
End IfReturn New NetworkCredential(userName, password, domain)
End Get
End PropertyPublic Function GetFormsCredentials(ByRef authCookie As Cookie, ByRef userName As String, ByRef password As String, ByRef authority As String) As Boolean Implements IReportServerCredentials.GetFormsCredentials
authCookie = Nothing
userName = Nothing
password = Nothing
authority = "Ntlm"Return False
End Function
End Class
I use this on http://www.easywebreports.com
Thursday, January 28, 2010 10:54 AM -
User1471311455 posted
FYI
The reason that is blowing up is because your type is wrong. You need to change:
Private _ParameterControlType As Type = System.Reflection.Assembly.GetAssembly(GetType(Microsoft.Reporting.WebForms.ReportViewer)).GetType("Microsoft.Reporting.WebForms.ParameterControl")
To:
Private _ParameterControlType As Type = System.Reflection.Assembly.GetAssembly(GetType(Microsoft.Reporting.WebForms.ReportViewer)).GetType("Microsoft.Reporting.WebForms.BaseParameterInputControl")
And that should get you up and running. And you can take out the try / catch if you'd like.
Thursday, January 28, 2010 12:46 PM -
User190544272 posted
1. Add assembly reference Microsoft.ReportViewer.WinForms
2. Add the namespace using Microsoft.Reporting.WinForms;
3. Add the below code.
public ReportParameter[] GetCurrentParameters(Microsoft.Reporting.WebForms.ReportViewer viewer) { Control params1Area = FindParametersArea(viewer); List<ReportParameter> params1 = new List<ReportParameter>(); FindParameters(params1Area, params1); return params1.ToArray(); } private Control FindParametersArea(Microsoft.Reporting.WebForms.ReportViewer viewer) { foreach (Control child in viewer.Controls) { if (child.GetType().Name == "ParametersArea") return child; } return null; } private Type _ParameterControlType = System.Reflection.Assembly.GetAssembly(typeof(Microsoft.Reporting.WebForms.ReportViewer)).GetType("Microsoft.Reporting.WebForms.ParameterControl"); private void FindParameters(Control parent, List<ReportParameter> params1) { ReportParameter param; Microsoft.Reporting.WebForms.ReportParameterInfo paramInfo; String[] paramValues; foreach (Control child in parent.Controls) { if (_ParameterControlType.IsAssignableFrom(child.GetType())) { paramInfo = (Microsoft.Reporting.WebForms.ReportParameterInfo)GetPropertyValue(child, "ReportParameter"); if (paramInfo == null) continue; paramValues = (string[])GetPropertyValue(child, "CurrentValue"); if (paramValues != null && paramValues.Length > 0) { param = new ReportParameter(); param.Name = paramInfo.Name; param.Values.AddRange(paramValues); params1.Add(param); } } FindParameters(child, params1); } } public object GetPropertyValue(object target, string propertyName) { return target.GetType().GetProperty(propertyName, System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public).GetValue(target, null); }
4. Invoke it asReportParameter[] reportParams = GetCurrentParameters(FactReportViewer);
Tuesday, November 2, 2010 7:54 PM -
User1137074964 posted
I cannot seem to do the following:
1) I have a report that uses the ASP.NET 2.0 Report Viewer against a RS2005 report that has parameters. Some have default values. One is a text box. Others are drop-down lists.
2) I have ShowParameterPrompts = true and am presented the parameter area upon first visit to the page.
3) I fill in the parameters on the web browser page and click the View Report button
4) Now, on the server side, I want to examine the parameter values (in the Page_Load event). When I do a GetParameters on the ServerReport of the ReportViewer, I receive back a collection of the default parameters values, not the values that I just submitted.How do I see the parameter values submitted by the client?
Other information I found while investigating this:
1) If I click on the View Report button again (and again), GetParameters always return the previous set of parameters, not the current values that the client submitted.
2) If I look at the Request.Forms collections I can see values for controls that have been generated by the ReportViewer control in the parameters area - where the values are different when the client submitts new parameters.
3) If I do a GetParameters in the pages Page_PreRender event, I see the same behavior.
4) I can do a walk of the control tree inside the report view control instance and see the various controls created for the parameters area. Those controls have the Request.Form values in them.
5) The Report Viewer, load, report refresh and prerender events don't seem to be much help either.I could hack a solution using the control tree or the Request.Form values, but that's rather inelegant and relies on Micrsoft not changing the ReportViewer control's behavior.
Any explanations of what is happening here would be appreciated. Thanks,
ER Doll
I implemented my own parameter processiong using SSRS 2008 web services. It's not an easy task but you have full control on report parameters. Please see an example.
Wednesday, November 3, 2010 5:01 PM -
User1808977555 posted
I tried all of the code in here, hoping that legacy code would still function work... Every parameter was private...
Then I browsed through intellisense and found this on the ReportViewer 11.0
ReportParameterInfoCollection parms = ReportViewer1.ServerReport.GetParameters();
Doh!
Monday, March 31, 2014 4:09 PM -
User-511518934 posted
An example for zoom parameter thats works for me:
protected override void OnPreRender(EventArgs e) { if (this.IsPostBack) { var paramCollection = this.GetCurrentParameters(this.ReportViewer1).ToList(); foreach (var param in paramCollection) { if (param.Name == "zoom") { var zoom = 100; if (param.Values.Count > 0) { int.TryParse(param.Values[0], out zoom); } this.ReportViewer1.ZoomPercent = zoom; break; } } } } public ReportParameter[] GetCurrentParameters(Microsoft.Reporting.WebForms.ReportViewer viewer) { Control params1Area = FindParametersArea(viewer); List<ReportParameter> params1 = new List<ReportParameter>(); FindParameters(params1Area, params1); return params1.ToArray(); } private static Control FindParametersArea(Control viewer) { foreach (Control child in viewer.Controls) { if (child.GetType().Name == "ParametersArea") { return child; } else { var contr = FindParametersArea(child); if (contr != null) { return contr; } } } return null; } private void FindParameters(Control parent, List<ReportParameter> params1) { ReportParameter param; Microsoft.Reporting.WebForms.ReportParameterInfo paramInfo; String[] paramValues; foreach (Control child in parent.Controls) { // for textbox use: child.GetType().Name == "TextParameterInputControl" // for combobox if (child.GetType().Name == "ValidValuesParameterInputControl") { paramInfo = (Microsoft.Reporting.WebForms.ReportParameterInfo)GetPropertyValue(child, "ReportParameter"); if (paramInfo == null) continue; paramValues = (string[])GetPropertyValue(child, "CurrentValue"); if (paramValues != null && paramValues.Length > 0) { param = new ReportParameter(); param.Name = paramInfo.Name; param.Values.AddRange(paramValues); params1.Add(param); } } } } private object GetPropertyValue(object target, string propertyName) { return target.GetType().GetProperty(propertyName, System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public).GetValue(target, null); }
GetCurrentParameters returns all ComboBox parameters.
Wednesday, June 25, 2014 12:23 PM