|
| 1 | +--- |
| 2 | +title: Change the Parameters Programmatically in Native Blazor Report Viewer |
| 3 | +description: "Learn how to change the Native Blazor Report Viewer parameter values programmatically by creating a new ReportSourceOptions object." |
| 4 | +type: how-to |
| 5 | +page_title: Pass the Parameters Programmatically in Native Blazor Report Viewer |
| 6 | +slug: change-telerik-native-blazor-report-viewer-parameters-values-programmatically |
| 7 | +tags: telerik reporting, reportviewer, parameters, native blazor, onparameterssetasync, reportsourceoptions |
| 8 | +res_type: kb |
| 9 | +ticketid: 1690218 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +<table> |
| 15 | + <tbody> |
| 16 | + <tr> |
| 17 | + <td>Product</td> |
| 18 | + <td>Progress® Telerik® Reporting</td> |
| 19 | + </tr> |
| 20 | + <tr> |
| 21 | + <td>Viwer</td> |
| 22 | + <td>Native Blazor Report Viewer</td> |
| 23 | + </tr> |
| 24 | + </tbody> |
| 25 | +</table> |
| 26 | + |
| 27 | +## Description |
| 28 | + |
| 29 | +I cannot get the [Native Blazor Report Viewer]({%slug telerikreporting/embedding-reports/display-reports-in-applications/web-application/native-blazor-report-viewer/overview%}) to refresh the report based on new parameter values after displaying the report with default parameters. When I update parameters programmatically. For example, using a dropdown—the report does not refresh, even though the [OnParametersSetAsync](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.componentbase.onparameterssetasync) method executes with the new parameter values. |
| 30 | + |
| 31 | +However, if I use the parameter input area in the Report Viewer interface, the report refreshes properly with the updated values. I need a way to programmatically pass new parameters and redisplay the report with these values. |
| 32 | + |
| 33 | +This knowledge-base article also answers the following questions: |
| 34 | + |
| 35 | +* How do I refresh the Native Blazor Report Viewer with new parameters? |
| 36 | +* Why doesn't the Native Blazor Report Viewer reflect parameter changes programmatically? |
| 37 | +* How can I pass changed parameters to Telerik Native Blazor Report Viewer? |
| 38 | + |
| 39 | +## Solution |
| 40 | + |
| 41 | +To refresh the [Native Blazor Report Viewer]({%slug telerikreporting/embedding-reports/display-reports-in-applications/web-application/native-blazor-report-viewer/overview%}) programmatically with new parameter values, ensure that you create a new `ReportSourceOptions` object when updating the `ReportSource` property. Modifying the existing object will not trigger the refresh. Below is an example demonstrating this approach. |
| 42 | + |
| 43 | +### Example |
| 44 | + |
| 45 | +>note While the example below is made using the [OnParametersSetAsync](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.componentbase.onparameterssetasync) lifecycle event, it is not required to use this Blazor event, or any event at all, the `ReportSource` can be edited outside the Blazor events as well as long as a new `ReportSourceOptions` object is provided. |
| 46 | +
|
| 47 | +Use the following code snippet in the [OnParametersSetAsync](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.componentbase.onparameterssetasync) lifecycle event: |
| 48 | + |
| 49 | +````C# |
| 50 | +protected override async Task OnParametersSetAsync() |
| 51 | +{ |
| 52 | + // Create a new ReportSourceOptions object with the updated parameters |
| 53 | + var rso = new ReportSourceOptions() |
| 54 | + { |
| 55 | + Report = "Report1.trdp", |
| 56 | + Parameters = new Dictionary<string, object> |
| 57 | + { |
| 58 | + {"Category", SelectedCategory} // Pass the updated parameter value |
| 59 | + } |
| 60 | + }; |
| 61 | + |
| 62 | + // Assign the new object to the ReportSource property |
| 63 | + ReportSource = rso; |
| 64 | + |
| 65 | + await base.OnParametersSetAsync(); |
| 66 | +} |
| 67 | +```` |
| 68 | + |
| 69 | +### Key Points |
| 70 | + |
| 71 | +1. Always create a **new** `ReportSourceOptions` object when updating the `ReportSource` property. |
| 72 | +1. Assign the updated parameter values to the `Parameters` dictionary within the new object. |
| 73 | +1. Ensure the `ReportSource` property references the new object to trigger the refresh. |
| 74 | + |
| 75 | +## See Also |
| 76 | + |
| 77 | +* [Native Blazor Report Viewer Documentation]({%slug telerikreporting/embedding-reports/display-reports-in-applications/web-application/native-blazor-report-viewer/overview%}) |
| 78 | +* [Embedding Reports in Blazor Applications]({%slug telerikreporting/using-reports-in-applications/display-reports-in-applications/web-application/blazor-report-viewer/how-to-use-blazor-report-viewer%}) |
0 commit comments