This is a migrated thread and some comments may be shown as answers.

Querystring parameter

5 Answers 114 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
david
Top achievements
Rank 1
david asked on 18 Apr 2016, 07:09 PM

I have Web Forms report viewer ASPX and I'm trying to set a parameter "Parameter1" included in the designer like this:

     if (!IsPostBack)
            {
                int AppointmentID = Convert.ToInt16((string)Request.QueryString["AppointmentID"]);
                ReportLibrary.ClientApptInvoice rpt = new ReportLibrary.ClientApptInvoice();
                rpt.ReportParameters["Parameter1"].Value = AppointmentID;
            }

when I run the report viewer page I get "Missing or invalid parameter value" and the parameter field which is set visible appears to allow entry.

What am I missing ? I was trying to follow this - http://docs.telerik.com/reporting/designing-reports-parameters-programmatic-control

Thanks

5 Answers, 1 is accepted

Sort by
0
Rick
Telerik team
answered on 19 Apr 2016, 09:15 PM
Hello David,

I see that you instantiate a new report in what looks like the Page_Load event, and I see where you set the parameter value for Parameter1. That all looks correct. I do not see where you actually set that newly instantiated report to be the source of the WebForms ReportViewer. The issue may be that you're not actually loading the same report that you're configuring.

Try configuring your code like the below. Note that I assign my new report to a ReportSource that is then used by the ReportViewer.

if (!IsPostBack)
{
    string fakeQueryString = "String Here";
 
    ClassLibrary1.Report2 rpt = new ClassLibrary1.Report2();
    rpt.ReportParameters["Parameter1"].Value = fakeQueryString;
 
    Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
    reportSource.ReportDocument = rpt;
 
    ReportViewer1.ReportSource = reportSource;
}


Regards,
Rick
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
david
Top achievements
Rank 1
answered on 19 Apr 2016, 09:27 PM

Rick, thank you, when i follow this (source below) I get an error on : reportViewer1.ReportSource = reportSource;

"Cannot implicitly convert type 'Telerik.Reporting.InstanceReportSource' to 'Telerik.ReportViewer.Html5.WebForms.ReportSource"

 

                ReportLibrary.ClientApptInvoice rpt = new ReportLibrary.ClientApptInvoice();

                rpt.ReportParameters["Parameter1"].Value = AppointmentID;
                Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
                reportSource.ReportDocument = rpt;
                reportViewer1.ReportSource = reportSource;

 

aspx

<telerik:ReportViewer
            ID="reportViewer1"
Width="1300px" Height="900px"             runat="server">
            <ReportSource IdentifierType="TypeReportSource" Identifier="ReportLibrary.ClientApptInvoice, ReportLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
            </ReportSource>
        </telerik:ReportViewer>

0
Rick
Telerik team
answered on 20 Apr 2016, 08:24 PM
Hi David,

There are two different ReportViewers that can be used in a WebForms project.
  • The classic ASP.NET Web Forms ReportViewer is a traditional server control with a full server object.
  • The newer HTML5 ReportViewer is a clientside object implemented in JavaScript. We also provide a server-wrapper for this widget for convenience, but it is still a clientside only object under the wrapper. (This seems to be the version you're using.)

There are several important differences between the two, so I recommend reading the linked articles carefully to choose the best ReportViewer for your application. However, since the HTML5 ReportViewer does not have a server object, you cannot assign an in-memory report to it directly in server code. When working with the HTML5 ReportViewer, you should set your parameter in JavaScript, and refresh the Report. If you're using the server wrapper for the widget, you can set these values in code, and all the JavaScript will be generated for you. Here is an example - which I recommend as a best-practice for new development.

if (!IsPostBack)
{
 
    Telerik.ReportViewer.Html5.WebForms.ReportSource typeReportSource = new ReportSource();
 
    typeReportSource.IdentifierType = IdentifierType.TypeReportSource;
    typeReportSource.Identifier = "ClassLibrary1.Report2, ClassLibrary1, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null";
 
 
    typeReportSource.Parameters.Add("Parameter1", "SetValueHere");
 
    reportViewer1.ReportSource = typeReportSource;
 
}



Regards,
Rick
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
david
Top achievements
Rank 1
answered on 20 Apr 2016, 09:07 PM

Thank you Rick!  This last set of sample code you sent did the trick, might be handy to add to the docs I spent hours looking at them and the forum posts and couldnt find it.

 

regards

if (!IsPostBack)
{

    Telerik.ReportViewer.Html5.WebForms.ReportSource typeReportSource = new ReportSource();

    typeReportSource.IdentifierType = IdentifierType.TypeReportSource;
    typeReportSource.Identifier = "ClassLibrary1.Report2, ClassLibrary1, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null";


    typeReportSource.Parameters.Add("Parameter1", "SetValueHere");

    reportViewer1.ReportSource = typeReportSource;

}

0
Rod
Top achievements
Rank 1
answered on 09 Nov 2017, 03:47 PM
Thank you for posting this. It was really hard to find a straight-forward example of this. Spent the last two hours figuring this out. Maybe time to switch to MVC or Core. Lots of example of that implementation.
Tags
General Discussions
Asked by
david
Top achievements
Rank 1
Answers by
Rick
Telerik team
david
Top achievements
Rank 1
Rod
Top achievements
Rank 1
Share this question
or