I have a razor page in my Blazor server app with a report viewer control on it (named AllowanceDetailViewer in the code below). I gather the desired parameter values for this report from the user on page 1 and then launch page 2 and pass it those values. On page 2 I want the report to display using the passed values when the page loads.
The issue is where do I put the call to the Refresh() function on page 2? If I put a call in OnInitializedAsync() I get an error that the AllowanceDetailViewer object is null (so it hasn't loaded yet). If I put a call in OnAfterRenderAsync() I get an internal error from the viewer control. Is there a page event I can use where the report viewer is fully loaded and ready for use?
Note: if I add a button to the page and call the Refresh() function from the button click it works fine. That tells me the code in the Refresh() function is working. What I want is to call that code during the initial page load so it happens automatically without the user needing to click on something first.
<ReportViewer @ref="AllowanceDetailViewer"
ViewerId="rv1"
ServiceUrl="api/reports"
ReportSource="@(new ReportSourceOptions
{
Report = "BlankReport.trdp"
})"
ScaleMode="@(ScaleMode.Specific)"
Scale="1.0"
ViewMode="ViewMode.Interactive"
ClientEvents= "@(new ClientEventsOptions() {Ready = "ReportReady"})"
/>
async Task Refresh()
{
rso.Report = "AllowanceDetail.trdp";
await AllowanceDetailViewer.SetReportSourceAsync(rso);
rso = await AllowanceDetailViewer.GetReportSourceAsync();
//code here setting a bunch of parameters, this is just a stub
rso.Parameters["parameter1"] = "new parameter value";
await AllowanceDetailViewer.SetReportSourceAsync(rso);
}