ActiveReports allows you to use scripting to provide VB.NET or C# functionality to reports without needing to use actual .vb or .cs files. This permits reports saved to an RPX (report xml) file to serve as stand-alone reports. By including scripting when the report is saved as an RPX file, it can later be loaded, run, and displayed directly to the viewer control without using the designer. In conjunction with RPX files, scripting allows distributed reports to be updated without recompiling.
ActiveReports for NET 3.0 loads RPX files, including any scripting, in the InitializeComponent() method. |
Scripting can be used by adding C# or VB.NET code to the script editor at design time or by using the rpt.Script property at run time. The script is then saved to the RPX file.
To access the script editor, click the script tab below the report design surface. |
Since the RPX file can be read with any text editor, the AddCode or AddNamedItem method should be used to add secure information, such as a connection string, to a project. |
Tips for Using Scripting
- Make sure the report class is public. If the report class is not set to public, the script will not be able to recognize the items in your report. The report class is public by default.
- Make sure the control being referenced in the script has its Modifiers property set to Public. If the control's Modifiers property is not set to Public, the control cannot be referenced in script and an error will be raised when the report is run. The Modifiers property has a default value of Private, so you must set this property in the designer.
- Use "rpt." The script must use rpt to reference the report instead of this (as in C# code-behind) or Me (as in VB code-behind).
- Use error handling. When working with scripting, use error handling around the .Run() call. When errors are raised, the returned error should point to the section of script causing the error.
See the following links to learn specifics of using the scripting capabilities of ActiveReports for .NET in your applications.
- Use ((ControlType)rpt.Sections[SectionName].Controls[ControlName]) to type cast a control and access its properties.
- Create classes inside the script to call methods.
- Use the AddScriptReference method to gain access to .NET (or other) namespaces.
- Use the AddNamedItem method to access class files in a project.
- Use AddCode to inject code into the script.