Add a Custom Edit Button to the Bold Reports Viewer Toolbar in .NET Core
Bold Reports® lets you add custom items to the ASP NET Core Report Viewer toolbar. You can add an Edit button that navigates to a Report Designer page and passes the path of the report currently displayed.
Applies to: Bold Reports ASP NET Core Report Viewer applications that also implement a Report Designer page.
Security: A toolbar button only controls the user interface; it does not grant or restrict edit permissions. Protect the designer page and its report-loading endpoint with server-side authentication and authorization. Validate the requested report path and confirm that the current user can edit that report. Do not rely on hiding the button as an access-control measure.
Before You Begin
- Configure the Report Viewer and Report Designer pages in your ASP NET Core application.
- Confirm that the user should have permission to edit the report before showing the Edit button.
- Identify the Report Designer route that loads the report to edit.
Step-by-Step Instructions
Step 1: Add a Custom Edit Button to the Toolbar
In your ASP.NET Core application, open Views/Home/ViewReport.cshtml and add a custom item to the existing toolbarSettings property. Merge this into your current toolbar settings so existing options are preserved.
toolbarSettings: {
showToolbar: true,
items: ej.ReportViewer.ToolbarItems.All,
customItems: [{
groupIndex: 6,
index: 5,
type: 'Default',
id: 'viewer_edit',
prefixIcon: "e-viewer-icons edit",
cssClass: "e-icon e-edit e-reportviewer-icon ej-webicon",
style: 'font-size:36px',
tooltip: { header: 'Edit', content: 'Edit the Report Design' }
}]
},
The groupIndex and index values are example positions; adjust them to fit the toolbar layout and product version used by your application.
| Property | Description |
|---|---|
items |
Includes the default Report Viewer toolbar items. |
customItems |
Defines custom toolbar items. |
groupIndex and index |
Set the group and item positions in the toolbar. |
id |
Identifies the custom item so the click handler can recognize it. |
prefixIcon and cssClass |
Set the icon classes for the button. |
style |
Sets the button’s inline font size. |
tooltip |
Sets the button’s tooltip heading and description. |
The customItems property adds a user-defined Edit button to the Report Viewer toolbar with custom styling, an icon, and a tooltip.
Step 2: Handle the Edit Button Click
Add a toolBarItemClick handler to the Report Viewer initialization. Merge the handler into the existing viewer options:
toolBarItemClick: function (args) {
if (args.value === "viewer_edit") {
var reportviewerObj = $("#viewer").data("boldReportViewer");
var reportPath = reportviewerObj.model.reportPath;
window.location.href = '/Home/DesignReport?name=' + encodeURIComponent(reportPath);
}
}
The handler checks for the custom item ID, reads the current report path, encodes it for use in a query string, and navigates to the designer route.
The #viewer selector must match the ID of your Report Viewer element. The name query parameter is untrusted input. In /Home/DesignReport, validate the report path and check that the authenticated user has permission to edit the requested report before loading it.
Code Explanation
| Code | Description |
|---|---|
toolBarItemClick: function (args) { ... } |
Handles a Report Viewer toolbar-item click. |
args.value === "viewer_edit" |
Checks whether the custom Edit item was clicked. |
$("#viewer").data("boldReportViewer") |
Gets the Report Viewer instance from the element with ID viewer. |
reportviewerObj.model.reportPath |
Reads the report path currently loaded in the viewer. |
encodeURIComponent(reportPath) |
Encodes the report path for use as a query-string value. |
window.location.href = ... |
Navigates to the Report Designer route with the report path. |
The click handler passes the current report path to the designer route. The destination must still verify the user’s edit permission and validate the path.
Toolbar Events
The following events can be used for additional toolbar customization:
- ToolbarClick: Triggered when a toolbar item is clicked. Use it to implement actions for default or custom items.
- ToolbarRendering: Triggered before the toolbar is rendered. Use it to add, remove, or modify toolbar items based on application requirements.
Step 3: Connect the Viewer and Designer Pages
To enable navigation between viewing and editing, configure both pages in your ASP NET Core application:
- Report Viewer page: In
Views/Home/ViewReport.cshtml, configure the Report Viewer with the custom toolbar item and click handler. - Report Designer page: In
Views/Home/DesignReport.cshtml, configure the Report Designer to load the selected report. Perform the server-side authorization check on this page and its report-loading endpoint.
Passing the Report Name
When a user clicks Edit, the viewer passes the report path to the designer page as a query parameter. For example:
/Home/DesignReport?name=SalesReport.rdl
Use the report path format and loading method supported by your application’s Report Designer setup.
The sample application uses Views/Home/ViewReport.cshtml for the Report Viewer and Views/Home/DesignReport.cshtml for the Report Designer. Adapt these paths and the report-loading logic to your application.
Preview
Run the application and open a report in the Report Viewer. If the current user is allowed to edit the report, verify that the custom Edit button appears in the toolbar.
Click Edit and verify that the application opens the designer with the intended report. Confirm that a user without edit permission cannot load or modify the report by navigating directly to the designer URL.
Conclusion
Adding a custom Edit button can provide a direct route from the Report Viewer to the Report Designer while preserving the report path. The destination page and report-loading endpoint must enforce edit permissions independently of the toolbar.
Download Sample
You can find the complete sample application here.