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

Accessing Code Behind Properties of Report in ReportViewer

7 Answers 449 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Shane
Top achievements
Rank 1
Shane asked on 26 Jan 2017, 07:25 PM

Hello,

I have made a report that has important properties in its code behind that I am attempting to access using "ReportDefinition.PropertyName" in expressions. This technique works perfectly in the Preview tab at design time, however in the Html5 WebForms ReportViewer control, this method of referencing properties always returns null. Note that 1) I know that the properties are not null, and 2) in the same report in the same control, I'm successfully referencing a method in the code behind that returns a string including some of the values of those same properties. Currently my references to ReportDefinition are mostly in TextBoxes, but moving them to report parameters does not solve the problem.

Example of an expression I'm using in a TextBox: '= IsNull(ReportDefinition.OrderNumber, "INVALID ID")'

Why can I successfully reference methods using ReportDefinition at both design time and run time, but only successfully reference properties at design time?

Thanks,

Shane

7 Answers, 1 is accepted

Sort by
0
Shane
Top achievements
Rank 1
answered on 27 Jan 2017, 01:18 PM

http://www.telerik.com/forums/using-a-member-variable-of-the-report-object

If confused about the problem, it is the same technique described in this thread. Whether I use ReportItem.Report.ItemDefinition.PropertyName or just ReportDefinition.PropertyName, my member variables return null when the report is in the ReportViewer, though they show up fine in the Preview tab. They also work fine if I programmatically generate a PDF of the same report.

And again, I have a method referenced in the same way that is returning the proper value.

 

0
Stef
Telerik team
answered on 27 Jan 2017, 02:00 PM
Hi Shane,

Most probably when you request the VS report through the HTML5 Viewer, you are using its assembly qualified name. Ther reporting engine will use reflection to create an instance of the report through its default parameterless constructor. Please check if the custom properties extending the report are set in that constructor.
For other scenarios, check How to display a report via InstanceReportSource in the HTML5 Viewer.

Regards,
Stef
Telerik by Progress
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
Shane
Top achievements
Rank 1
answered on 27 Jan 2017, 02:15 PM

Hi Stef,

This is likely the problem. I started experimenting with the constructor, but nothing has helped so far. Could you please give an example of what my parameterless constructor should look like if I have custom properties?

Another note, I have the same issue when trying to display the report in the WPF ReportViewer, so I don't think it's an issue specifically for the HTML5 viewer.

Thank you!

0
Shane
Top achievements
Rank 1
answered on 27 Jan 2017, 02:18 PM
(Right now, I have not set any of the custom properties in the default constructor.)
0
Shane
Top achievements
Rank 1
answered on 27 Jan 2017, 02:18 PM
(Right now, I have not set any of the custom properties in the default constructor.)
0
Stef
Telerik team
answered on 27 Jan 2017, 05:07 PM
Hello Shane,

The idea is that to display a report, you need a Report Source object. If it is a TypeReportSource, the processed report will be created through the default parameterless constructor of the report class and to use an expression like "=ReportDefinition.Test", the property must be set in the default constructor:

public partial class Report1 : Telerik.Reporting.Report
  {
 
      public string Test { get; set; }
      public Report1()
      {
          //
          // Required for telerik Reporting designer support
          //
          InitializeComponent();
          Test = "test 123";
      }
  }



Regards,
Stef
Telerik by Progress
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
Shane
Top achievements
Rank 1
answered on 27 Jan 2017, 05:22 PM

Ah, I see. That makes sense now with what I've experienced in trying different things out. I'll try and find a workaround that allows me to do this, as I do not currently set them in the constructor. Thank you for the information.

Tags
General Discussions
Asked by
Shane
Top achievements
Rank 1
Answers by
Shane
Top achievements
Rank 1
Stef
Telerik team
Share this question
or