Show toast on initialized
Hi, On a Blazor webassembly project , I'm trying to show a toast when the page component is loaded, but I got error "Object reference not set to an instance of an object.". I have tried it on different events like OnInitializedAsync, OnAfterRender, OnParametersSetAsync, but on all the events the toas object is null.
Here is my code, thank you.
<SfToast ID="alertMessage" @ref="@ToastObj" Title="Client" Content="@ToastContent">
<ToastPosition X="Center" Y="Top"></ToastPosition>
</SfToast>
@code {
SfToast ToastObj;
private string ToastContent = "Client has been added successfully";
private async Task OnInitializedAsync()
{
await this.ToastObj.Show();
}
private async Task OnParametersSetAsync()
{
await this.ToastObj.Show();
}
protected override void OnAfterRender(bool firstRender)
{
this.ToastObj.Show();
}
}
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
RK
Revanth Krishnan
Syncfusion Team
January 27, 2021 06:48 AM UTC
Hi Luis,
Greetings from Syncfusion support.
We have validated your query “Need to show Toast on initialized when the page component is loaded”.
This can be achieved using the ‘Created’ event of the Toast to show the Toast when the page component is loaded. We have prepared a sample for your reference,
Code Snippet:
|
@using Syncfusion.Blazor.Notifications
<SfToast ID="alertMessage" @ref="@ToastObj" Title="Client" Content="@ToastContent" Timeout="10000">
<ToastEvents Created="@onCreate"></ToastEvents>
<ToastPosition X="Center" Y="Top"></ToastPosition>
</SfToast>
@code {
SfToast ToastObj;
private string ToastContent = "Client has been added successfully";
private async Task onCreate()
{
await this.ToastObj.Show();
}
} |
Please check the above code snippet and the sample and let us know if it satisfies your requirement.
Regards,
Revanth
Marked as answer
LR
Luis Roberto
January 27, 2021 03:07 PM UTC
It worked great, thank you very much, I really appreciate your help.
Take care
RK
Revanth Krishnan
Syncfusion Team
January 28, 2021 09:05 AM UTC
Hi Luis,
Thank for the update.
Please let us know if you need any further assistance.
Regards,
Revanth
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
- Marked answer
-
LR Luis Roberto
- Jan 26, 2021 08:31 PM UTC
- Jan 28, 2021 09:05 AM UTC