Handle Events via Scripts
- Last UpdatedMar 30, 2022
- 3 minute read
Report Designer includes a scripting feature to handle the events of report controls, report bands, or reports themselves. The basic principles of scripting are described in this topic.
Overview
Scripting enables the user to insert scripts into a report, and execute them when the report is previewed, printed or exported. Script commands should be placed within the event handlers of the report objects. When the corresponding event occurs (e.g. a mouse click), the script code runs.
Generally scripts are used for data-aware report formatting. Though Report Designer enables users to perform such tasks without any scripting (see Conditionally Change a Control's Appearance, Conditionally Change a Label's Text and Conditionally Hide Bands), sometimes it may be required to use scripts, for example to achieve more specific results. The report's layout can be fully customized using of scripting.
Scripting also is the only way to calculate custom summaries.
Every report object has a set of events that can result in a script being run. The set of events depends on a particular element type. For example, the Label control's events are shown in the following image:

To add a script for an event, select New from the drop-down lost for that event. Once a script is added for an event it will be added to this drop-down list. To select and edit an existing script for an event, select it from the drop-down list for that event.
The Scripts tab is then displayed:

The tab displays a script template in the language specified by the Script Language property of the report (C#, Visual Basic or JScript .NET).
Insert or amend the script code with the help of this simple editor. Use the Validate button to check for any errors. If there are any, they will be displayed in the Script Errors tab.

If there are errors in the script, an error message will also be displayed on previewing the report.

The drop-down lists at the top of the Scripts tab are used to select other report elements and to select and add other event scripts.
The scripts are saved along with the report layout to a file (for further information on this, refer to Back up the Current Layout before Modification).
Note:
Assembles do not usually need including, because most standard assemblies that may
be required in scripts are already referenced by the Report Designer.