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?
7 Answers, 1 is accepted
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.
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.
Telerik by Progress
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.
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:
Telerik by Progress
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.