I cannot show tast after page render

I try to show tast just after page render on ServerPrerendered Blazor application.
I understand that it will not work while Toast object will not be rendered, so I use OnAfterRender event and check the first render.
Toast is not shown.

I tried to use delay and alternatively timer to ensure that toast will be requested after all content will be rendered and all java scripts finished. Anyway toast is not shown.

Could you make an example of right usage of toast to call it on page load?



5 Replies 1 reply marked as answer

IS Indrajith Srinivasan Syncfusion Team August 18, 2020 06:50 AM UTC

Hi Stanislav, 
 
Greetings from Syncfusion support, 
 
We have validated your reported query. We suggest you to use the OnAfterRenderAsync blazor lifecycle method, with a minimal delay to show the SfToast after the page loads. We have also prepared a sample that tries to meet your requirements. 
  
 
 
Please let us know if the solution helps, 
 
Regards, 
Indrajith 



SG Stanislav Gordenko August 24, 2020 07:00 PM UTC

Thank you for idea. I have tested it and found it not useful. I work on ServerPrerendered Blazor application. In different situation delay of toast show should be different. Thus I should choose maximal delay.
If I use syncronous method to make Delay it stops another rendering. If I try to make the method of creating toast asyncronous - it followed by conflict between few threads, which could not be solved by simple InvokeAsync just before Toast.Show().

Your toast component has IsRendered property and I  decided to use it. I do the next:

        SfToast MessageToast;
        Queue<ToastModel> Queue = new Queue<ToastModel>();

    protected override void OnAfterRender(bool firstRender)
    {
        base.OnAfterRender(firstRender);
        if (firstRender)
        {
            while (Queue.Count > 0)
            {
                MessageToast.Show(Queue.Dequeue());
            }
        }
    }

    private void ShowToast(string Message, ToastLevel Level, int VisibleTimeOut = 0)
    {
         ToastModel toast = new ToastModel { ... };

        // other toast details depending on received content

        if (!MessageToast.IsRendered)
            Queue.Enqueue(toast);
        else
        {
            MessageToast.Show(toast);
        }
    }

I am not sure that I do the right way because it looks like AfterFirstRender fires before IsRendered is triggered. If so, please, show me the write way to catch IsRendered changing event.

By the way, I found that if toast has fixed properties inside it, is it not possible to change them and to show toast with this new porperties. First values are shown each time. I should use ToastModel only to change toast. Moreover, fixed and model properties could not be used together, in this case fixed values will be owerritten by default values from model. It is opposite to Dialog and could not be obvious after it.



GK Gunasekar Kuppusamy Syncfusion Team August 25, 2020 04:56 PM UTC

Hi Stanislav, 
Greetings from Syncfusion support, 

Query 1: 
I am not sure that I do the right way because it looks like AfterFirstRender fires before IsRendered is triggered. If so, please, show me the write way to catch IsRendered changing event. 

 
We have further validated your reported query. The Toast `IsRendered` property will be updated in the `Opened` event alone. So, we suggest you maintain a private variable and update this value in the Created event to check whether toast is rendered or not. 

 
Query 2 : 
I found that if toast has fixed properties inside it, is it not possible to change them and to show toast with this new properties. First values are shown each time. I should use ToastModel only to change toast. Moreover, fixed and model properties could not be used together, in this case fixed values will be owerritten by default values from model. 

 
We have checked this reported query from our end. The ToastModel values in the current toast are replaced with the fixed values used in the tag. So, we have suggested you pass needed values from the ToastModel instead of using fixed property values. 

 
We have also prepared a sample by achieving your requirements and attached it. 

 

 
Kindly check the above sample and confirm whether it meets your requirements 

 
Regards, 
Gunasekar K 


Marked as answer

RG Rob Gross replied to Indrajith Srinivasan October 28, 2021 03:16 AM UTC

Hi Indrajith,


Thank you for the sample, it has fixed a similar issue I was experiencing.


Is there any plan to change the SfToast component so that it renders correctly via OnAfterRenderAsync without needing to use a Task.Delay? Using Task.Delay seems like a bandaid fix when it is expected that SfToast would render via OnAfterRenderAsync without needing to add a Delay.


Regards,
Rob



GK Gunasekar Kuppusamy Syncfusion Team October 28, 2021 05:14 PM UTC

Hi Rob,

We have already improved the toast performance in the 18.3.35 version. So can you please upgrade the toast version to 18.3.35 or the latest version?


Now, You can render a toast without a time delay. Please let us know if you have any concerns.

Regards,
Gunasekar


Loader.
Up arrow icon