Hi 929Free
Thank you for reaching out to Microsoft Q & A forum.
To enable automatic closure of the toast via C#, you can update your JavaScript function to accept a timeout value:
function ShowChangeDeptStatusTipToastsWithTimeout(durationInMs) {
const toastEl = document.getElementById('deptStatusChangeTip');
if (!toastEl) return;
const toast = new bootstrap.Toast(toastEl, { autohide: true, delay: durationInMs });
toast.show();
}
Then, from your Blazor C# code, you can invoke it like this:
showTipMessage = "TestMessage";
StateHasChanged();
await JSRuntime.InvokeVoidAsync("ShowChangeDeptStatusTipToastsWithTimeout", 3000); // 3 seconds
This will display the toast message and automatically dismiss it after the specified duration.
If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.