gib_stu01
gib_stu01

Reputation: 81

Blazor Bootstrap offcanvas not refreshing content

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:

  1. Take the ID of the entry in row that was clicked, and call a method that fetches the data that can display the entry as a pdf
  2. Assign the pdf data to an object that holds it, this object is in turn what the TelerikPDFViewer control is bound to
  3. Call the ShowAsync method of the offcanvas control to make the offcanvas appear on screen, thereby displaying the PDF

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

Answers (1)

Leandro Requena
Leandro Requena

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

Related Questions