ASP.NET ReportViewer Parameter Prompt doesn't show - asp.net

I've been looking for this answer for a couple days now and I've been getting little bits of information that make it seem that you can have ReportViewer Control automatically prompt for the report's parameters. Just everything that I've tried and found doesn't seem to work. I've gotten the Parameter Prompts to work on a Windows Form but I just cannot get it to work in ASP.NET
I guess I'm simply asking can you get Report-viewer's Parameter Prompts to work in ASP.NET? if so, How?
I know you can do it manually, it's just, I feel if you can make ReportViewer Prompt automatically why program it yourself?
Edit: this is for local processing btw.

Prompting for parameters is not supported in local processing mode.
In article Report Parameters Dialog Box (Visual Studio Report Designer), which is invoked by clicking the Help button on that dialog, it says in the introductory text that:
The parameters properties that you specify in the Report Parameters
dialog box become part of the report definition. Some properties are
intended for programmatic use only. In contrast with reports that are
processed on a remote report server, a locally processed report does
not have a parameter input area used for selecting or typing parameter
values.
A little testing shows me that the default values specified for the parameters will be used, unless you modify them programmatically. I could not find an explanation on this design decision. If you want to use local processing, and prompt for user input, I would recommend to follow this solution:
I you embed the reports in a ReportViewer Control, you can put it on a page or form and add custom input controls to that page or form to gather report parameters. In the code-behind files, you will then pass the parameter values using code like this:
List<ReportParameter> parameterList = new List<ReportParameter>();
List<string> selectedProductTypes = listboxProductTypes.GetSelectedValues();
ReportParameter productTypes = new ReportParameter("ProductTypes", selectedProductTypes.ToArray(), false);
ReportParameter username = new ReportParameter("Username", "<current user>", false);
parameterList.Add(productTypes);
parameterList.Add(username);
reportViewer.LocalReport.SetParameters(parameterList);
In this example, you can see how to pass a multi-valued parameter, the values of which are taken from a multi-select ListBox.

You can also create a page that has the controls to gather the parameter input, put them in a set session variables and then transfer to the page that has the report viewer.
use object data source and set the parameter source as Session.
The only code you need to write is filling the session variables.

Related

SSRS - Pass Multi Value Parameter with Available Values Option Enabled Through Querystring

I have one Parameter on my report, that has multi value on.
And it's values came from a Dataset.
On my application, when I request a report, this parameter goes as an Querystring value. But when I use the multi value option, the parameter is not a single value anymore, but an "array" with multiple values (Of Couse).
REPORT?codArea=&codDiretoria=17&ultimaAlteracao=on&formato=PDF&codListaPrioridade=8&codListaPrioridade=13
Important Part:
(codListaPrioridade=8&codListaPrioridade = 13)
The issue, is the "Available Values" option. The Parameter having an Array as a value, don't have any of the "Available Values" and SSRS throw a error.
Important Part:
System.ServiceModel.FaultException: This report requires a default or user-defined value for the report parameter 'codListaPrioridade'. To run or subscribe to this report, you must provide a parameter value.
If i disable the "Available Values" option, i can send this "array" without any issue:
codArea=&codDiretoria=17&ultimaAlteracao=on&codListaPrioridade=9&codListaPrioridade=13&formato=PDF
Important Part:
(codListaPrioridade=9&codListaPrioridade=13)
="----> "& Join(Parameters!codListaPrioridade.Value, ",")
The trick is that I need create in this report, this parameter with "Available Values" enabled, but this parameter need to accept "Any" values (Because the Array that is coming on querystring).
The "Available Values" must be used to show which values are available only (Inside my application).
Inside SSRS, the parameter works fine, the issue only occurs when using this report in my application, sending the parameters values in a querystring.
The key part of the error is "This report requires a default or user defined value for the report parameter."
You don't need a default parameter. It sounds to me like your application is passing an invalid parameter value to the report. The reason it works when you disable the available values is because then it will accept ANY value at all.
Run the query that populates the available values and keep it open.
Set a breakpoint in your ASP.NET code just before it passes the values to the report server. Examine what those values are and make sure it isn't trying to pass anything that ISN'T in the list of available values you got from running the query.
If there is something different then that is the cause of your error. I can't remember off the top of my head if casing matters so you'll want to check that too. And if you check them and everything is fine... check them again. I don't know how many times I've thought there wasn't any data out of place only to suddenly see it later.
An alternate theory would be that you just aren't passing the multi-value parameter to the report server correctly. I've never tried to do it directly in the URL before but on the MSDN page Pass a Report Parameter Within a URL in the "other examples" section it shows passing a multi-value parameter. In their example they seem to append a number to the end of the parameter name for each value. But I'm not sure if that is right either.
https://myserver/Reportserver?/SQL+Server+User+Education+Team/_ContentTeams/folder123/team+project+report&teamgrouping2=xgroup&teamgrouping1=ygroup&OrderID=747&OrderID=787&OrderID=12
But since you're already writing .NET code let me make a suggestion. Use the webservice as a webservice. It makes things like this so much easier. You just add the web service as a reference to the project and then basically call it like any other .NET class. The reference reads the WSDL file and shows you all of the available API calls and their parameters and what you'll get back. It really is quite a nice feature. Check out this MSDN article on "How to: Add a Reference to a Web Service" and then this TechNet dev guide: https://technet.microsoft.com/en-us/library/bb522713.aspx

SSRS report fails to render via URL access unless View Report is clicked

The hyperlink to my SSRS report correctly renders parameters passed in on the URL query string. But the report does not render unless the View Report button is clicked. Other reports render as expected so I suspect something is wrong with the URL of the problem report:
http://reportserver/ReportServer/Pages/ReportViewer.aspx?%2fSales+Mgr+Reports%2fCustomer+Product+Variance+with+Net+Margin+Report&rs:Format=HTML4.0&rs:Command=Render&ReportType=PD&SortType=P&CurBeginDate=04/15/2013&CurEndDate=04/15/2014&CusCode=XXXXXXXXXX
That URL correctly fills the reports required parameters:
Why does this report fail to render even though I've included the command rs:Command=Render?
Thanks in advance.
Nevermind...I figured it out. Someone else might benefit though...
Blank parameters cannot be omitted from the query string. The two blank parameter boxes (Product Desc and Product ID) must be passed in with no value in order to make the render command work. It appears this is necessary even though those parameters are not required to run the report.
So the working query string has two (blank) parameters added on the end and looks like this:
http://reportserver/ReportServer/Pages/ReportViewer.aspx?%2fSales+Mgr+Reports%2fCustomer+Product+Variance+with+Net+Margin+Report&rs:Command=Render&rs:Format=HTML4.0&ReportType=PD&SortType=P&CurBeginDate=04/15/2013&CurEndDate=04/15/2014&CusCode=XXXXXXXXXX&ProdDesc=&ProdID=

How to add parameters to SSRS URL in report viewer?

In reference to this article:
http://msdn.microsoft.com/en-us/library/ms252072(VS.80).aspx
I can access my SSRS report from my Web Application but the problem is it does not accept the parameters in the URL.
here is the format that it accepts
Report Server URL:
http://ABCD.com/reportserver
Report Path:
/Company works/Sales report/ABC
Can anyone help me?
I want to pass parameters in the SSRS url through report viewer.
You can not pass parameters via the URL since the control is expecting on the URL to the actual reportserver and nothing more.
Example:
serverReport.ReportServerUrl = new Uri("http://ABCS.com/reportserver");
serverReport.ReportPath = "/AdventureWorks Sample Reports/My Report";
You can pass these parameters in your code behind though by using the ReportViewer.ServerReport.SetParameters() function. Here is a snippet of code I used for this purpose:
var parametersCollection = new List<ReportParameter>();
//add generic parameters that every report needs
parametersCollection.Add(new ReportParameter("RandomizerString", new Random().Next().ToString(), false));
parametersCollection.Add(new ReportParameter("MachineName", Request.UserHostAddress.ToString(), false));
ERDashboard.ServerReport.SetParameters(parametersCollection);
can't seem to add a comment to Sam's answer so I'll post another:
The ReportViewerControl ReportServerURL property is a lot different than formatting a general URL to access a report. You could use the logic that sam has provided to navigate a web browser control to that URL which would also render the report within your web app. It's another to try if you want.
As a note there are various reasons that you may choose a webbrowser control vs a reportviewer control. The reportviewer control is a lot easier to manage in the code-behind, but there is a memory issue when refreshing a report for extended periods of time (lots of information through google about memory leaks). This is the scenario where I have instead used the webbrowser and manually formatted URLs to pass parameters instead.

Send query string parameter from a non-web application

Ok, I've been bugging with this for too long.
I need to call my website from a rough VB.net app. Then only thing I need is to attach a query string parameter to the calling url, so I can distinguish the pages to be shown to different VB app users.
So I want to click a button and launch that website, giving this parameter.
First I was bugging with adding the system.web libraries. Now I can't use Request/Response.QueryString as well.
I tried getting some example help from this post. but as I said before - I cannot make use of Request.QueryString as I cannot import it.
I am stuck here:
Process.Start("http://localhost:56093/WebSite1?id=")
I need to attach a query string parameter to the url and then open the website with that url.
Can someone just give me a sample code for my problem.
Query parameters are parsed by the web server/http handler off the URL you use to call the page. They consist of key and value pairs that come at the end of the URL. Your code is nearly there. Say you needed to pass through the parameters:
ID = 1234
Page = 2
Display = Portrait
Then you'd turn them into a URL like this:
http://localhost:56093/WebSite1?ID=1234&Page=2&Display=Portrait
Therefore in your code you'd have:
Process.Start("http://localhost:56093/WebSite1?ID=1234&Page=2&Display=Portrait");

Adding a condition in the url

I would line to add a test condition in an asp.net form such that:
1) From page1.aspx I manually add a query string parameter so that I can trigger the rest of the process in test mode like so: page1.aspx?test=true . This flag must be added in the query string.
2) When I click on a asp.net button in page1.aspx, I am redirected to page2.aspx in test mode
because of teh attached querystring
It seems that I have to work around the postback model of asp.net this is not very straight forward.
Any idea how I can achieve the above behavior?
Thanks
It sounds like you're using a form that posts, but you want to stay in "test" mode. That is, you're not using HTTP-GET so it's not realistic to pass QS variables around.
What I'd do is stash a variable in your Session to set the user's session test mode. So adding &test=true would trigger a Session["TestMode"] = true; before you move to the next page.
Try this (in server-side code)
Response.Redirect("Page2.aspx?Test=" + Request.QueryString["Test"]);

Resources