How to handle errors when calling WebReport.DesignerSaveCallBack
Online Designer is an excellent tool for creating reports on the Internet. Let's look at the situation. You create a report template, save it, and ... See the message "was not saved". But what is wrong? How do you know what the error is? Now, the web report has the Debug property, with which you can "catch" errors right in the online report designer.
We need to enable the WebReport.Debug property and create an error handler in the method of saving the report. The error will be passed to the designer when the WebReport.DesignerSaveCallBack event is called.
Let's look at the process of saving a report from an online designer in a simplified way, then it happens like this:
1. Press the button to save the report in the report designer;
2. The designer calls our handler while saving;
3. The handler processes the report and calls a callback in the MVC application;
4. If an error occurs, it is sent to the handler;
5. The handler sends an error to the online designer.
Let's look at an example. Create an ASP.Net MVC application.
Open the controller HomeController.cs. Preliminarily add links to the FastReport and FastReport.Web libraries in the links. The section «uses» will contain the following links:
In the Index method, we will create an empty report and open it in the online designer (OnlineDesigner). But, beforehand, you need to add an online designer to the project. Unzip the downloaded online designer into the WebReportDesigner folder at the root of the solution:
Now we need a method of saving the report in Online Designer:
Here, we add error handling. To return an error to an online designer, you need to throw an exception:
For this action, we create a separate view named SaveDesignedReport.cshtml and the following code:
Now consider the view for the Index page (Home-> Index.cshtml):
At the top we display the title of the page. Next, we display the report received from the controller.
In the file _Layout.cshtml you need to connect scripts:
Now you need to make changes to the two web configs. The files are called the same, but they are located in different folders. The first one is located in the Views folder. Add to it:
The second file is located at the root of the project. In it we add a handler:
Run our application.
Go to the "Report" tab. Click "Save". The first time should be successful. Press the save button again. And we get an error. From the text it is clear that the report template file with this name already exists.
So we got a debugging tool for our reports and the web application as a whole.