Accessing toast via a service does not show the toast.
I have followed the instructions here How to show or hide any page using Blazor Toast? to be able to show a toast from any component in my Blazor server application. However, invoking the ShowToast on the ToastService does not show the toast. I can set a breakpoint on Toast.ShowAsync(); in the toast component and it does get called but I see nothing. At present, the toast component is located at the bottom of my MainLayout.razor file.
Curiously, if I move the toast component into my side bar, I *always* see a white box in my nav menu and looking at the HTML in the browser, I can see this is the toast component !
Can anyone help me get this working?
Andy
SIGN IN To post a reply.
3 Replies
PK
Priyanka Karthikeyan
Syncfusion Team
May 8, 2026 01:59 PM UTC
Hi Andrew Fraser,
Based on your issue description, this appears to be a common problem with toast component rendering in Blazor server applications. The issue is likely related to the placement and rendering of the toast component in your MainLayout.razor file.
There are several potential solutions:
Check Z-Index Settings:
When toast isn't visible or appears as a persistent white box, it's often due to z-index issues. Try adding these CSS rules to ensure proper stacking:
.e-toast-container {
z-index: 1000000001 !important;
}
Render Mode Issue:
The behavior might be occurring because the default render mode in Blazor server app is set to ServerPrerendered, which can cause the component to be initialized twice. You can modify your initialization method in the toast component:
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
ToastService.ShowToastTrigger += (ToastOption options) =>
{
InvokeAsync(() =>
{
this.options.title = options.title;
this.options.content = options.content;
this.isToastVisible = true; this.StateHasChanged(); this.toast.ShowAsync();
});
};
}base.OnAfterRender(firstRender);
}
Component Placement:
Make sure your ToastComponent is placed outside of any container that might affect its visibility. In your MainLayout.razor, it should be placed as a direct child of the root element:
@inherits LayoutComponentBase
@using BlazorApp.Components;
<PageTitle>BlazorApp</PageTitle>
<div class="page">
<div class="sidebar">
<NavMenu />
</div>
<main><div class="top-row px-4"><a rel='nofollow' href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
</div>
<article class="content px-4">
@Body
</article>
</main>
</div>
<ToastComponent />
Alternative Implementation:
If the issue persists, try creating a separate component for the toast and reference it in pages where you need it, rather than placing it in MainLayout.
For toast appearing as a persistent white box, ensure you're properly handling the show/hide state in your component and that your CSS isn't interfering with the toast's visibility or styling.
If the issue still persist,
- Provide a minimal reproducible sample with clear steps to reproduce the issue
- Share a video illustration of the problem for our better understanding
Thank you for your patience, understanding, and cooperation. We look forward to assisting you further if needed.
Regards,
Priyanka K
AF
Andrew Fraser
May 8, 2026 03:27 PM UTC
Priyanka K
Thank you for your suggestions. I was unable to make it work with the toast on the main layout I suspect because of the render mode (OnAfterRender was not being called) but putting the toast component on the pages I require a toast to be shown seems to work fine.
Thanks for your help.
PK
Priyanka Karthikeyan
Syncfusion Team
May 11, 2026 03:07 PM UTC
Hi Andrew Fraser,
Thank you for the update, and we're glad to hear that you found a working solution!
Your approach of placing the ToastComponent directly on the pages where it's needed is indeed a valid workaround. You've correctly identified that the render mode behavior was preventing the
OnAfterRender lifecycle method from being called as expected, which was causing the initialization issue in MainLayout.This page-level implementation actually provides better control and can be more efficient since the toast component is only rendered when needed, rather than globally in the main layout.
A few tips moving forward:
- If you need to share toast notifications across multiple pages, consider using a centralized service (like the
ToastServiceyou're already using) to manage the state - Keep the CSS z-index rules we mentioned in mind if you encounter any visibility issues in the future
Thank you for your patience and understanding. If you encounter any other issues or have questions about Syncfusion components, please don't hesitate to reach out. We're here to help!
Regards,
Priyanka K
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
AF Andrew Fraser
- May 8, 2026 08:35 AM UTC
- May 11, 2026 03:07 PM UTC