Reputation: 81
In a blazor server project i am using a TelerikPDFViewer control inside of a blazor bootstrap offcanvas control. The idea is that by clicking on a button within a grid a method is called that will:
The issue i am having is that when the ShowAsync method is called with await, the displayed PDF does not refresh. If i omit the await keyword on this method then it does refresh but i do not understand why.
Below is the method that is called when the grid row button is clicked. As it is the PDF is displayed correctly the first time it is called but when clicking buttons from other rows in the grid, the displayed PDF does not change. However if i remove the await keyword from pdfViewerWindow.ShowAsync(); then it does refresh correctly each time.
private async Task ViewTOPCasePDFHandler(GridCommandEventArgs args)
{
TOPCase item = args.Item as TOPCase; //Get item from row in whihc the View PDF button was clicked
string pdfBase64String = await _topService.GenerateFormCompletedPDF(item.CaseID); //Call method to get the PDF content
pdfViewerModel = new PdfViewerModel() //Assign PDF content to model that is in turn bound to the Telerik PDF Viewer
{
PdfSource = Convert.FromBase64String(pdfBase64String),
DownloadFilename = Convert.ToDateTime(item.CreatedDate).ToString("yyyy_MM_dd") + "_MyForm_" + item.CaseID.ToString()
};
await pdfViewerWindow.ShowAsync(); //Show the offcanvas panel
}
Upvotes: 0
Views: 232
Reputation: 398
After you change the Data
assigned to the TelerikPdfViewer
, you should call it's Rebind
method to refresh the PDF Viewer and ensure it is displaying the latest file Data
.
/** <TelerikPdfViewer @ref="@PdfViewerRef" Data="PdfSource"> **/
private TelerikPdfViewer PdfViewerRef { get; set; }
private async Task ViewTOPCasePDFHandler(GridCommandEventArgs args)
{
TOPCase item = args.Item as TOPCase; //Get item from row in whihc the View PDF button was clicked
string pdfBase64String = await _topService.GenerateFormCompletedPDF(item.CaseID); //Call method to get the PDF content
pdfViewerModel = new PdfViewerModel() //Assign PDF content to model that is in turn bound to the Telerik PDF Viewer
{
PdfSource = Convert.FromBase64String(pdfBase64String),
DownloadFilename = Convert.ToDateTime(item.CreatedDate).ToString("yyyy_MM_dd") + "_MyForm_" + item.CaseID.ToString()
};
PdfViewerRef.Rebind();
await pdfViewerWindow.ShowAsync(); //Show the offcanvas panel
}
Upvotes: 0