Radzen dialog & notification not working

Hi guys,

For the past hours I have been trying to learn why the Dialog & Notification are not working on the page below.

Info: new blazor web app visual studio template with rendermode auto, per page/component. I followed the official docs and the mainlayout and program.cs are adjusted.

@page "/users"
@rendermode InteractiveServer

@using IsdWebApp.Components.Models
@using IsdWebApp.Components.Dialogs
@using Microsoft.Extensions.Configuration
@using SqlDataAccess

@inject NotificationService NotificationService
@inject DialogService DialogService
@inject IDataAccess _data
@inject IConfiguration _config

@if (users == null)
{

All users


}
else
{

All users

<RadzenDataGrid @ref="grid" AllowColumnResize="true" AllowAlternatingRows="false" AllowSorting="true" PageSize="10" AllowPaging="true" PagerHorizontalAlign="HorizontalAlign.Left" ShowPagingSummary="true"
                Data="@users" TItem="UserModel" ColumnWidth="100px" SelectionMode="DataGridSelectionMode.Single" @bind-Value=@selectedEmployees>

    <HeaderTemplate>
        <RadzenCard Variant="Variant.Flat" Class="rz-my-1 rz-mx-1">
            <RadzenStack Orientation="Orientation.Horizontal" JustifyContent="JustifyContent.Start" Gap="1rem" Class="rz-p-1">
                <RadzenButton Text="Create" Click=@CreateUser Icon="add" ButtonStyle="ButtonStyle.Primary" Size="ButtonSize.Small" />
                <RadzenButton Text="Edit" Click=@(args => EditUser(selectedEmployees[0].userID)) Icon="edit" ButtonStyle="ButtonStyle.Primary" Size="ButtonSize.Small" />
                <RadzenButton Text="Delete" Click=@(args => DeleteUser(selectedEmployees[0].userID)) Icon="delete" ButtonStyle="ButtonStyle.Primary" Size="ButtonSize.Small" />
            </RadzenStack>
        </RadzenCard>
    </HeaderTemplate>

    <Columns>
        <RadzenDataGridColumn TItem="UserModel" Property="userID" Title="ID" Width="25px" />
        <RadzenDataGridColumn TItem="UserModel" Property="userFirstname" Title="First Name" />
        <RadzenDataGridColumn TItem="UserModel" Property="userLastname" Title="Last Name" />
        <RadzenDataGridColumn TItem="UserModel" Property="userRole" Title="Job Title" />
        <RadzenDataGridColumn TItem="UserModel" Property="userEmail" Title="Email" />
        <RadzenDataGridColumn TItem="UserModel" Property="userColor" Title="Color" />

    </Columns>
</RadzenDataGrid>

}

@code {
IList selectedEmployees;
RadzenDataGrid grid;
IEnumerable users;

protected override async Task OnInitializedAsync()
{
    //Get initial data, maybe later put in method
    string sql = "select * from users";
    users = await _data.LoadDataIEnumerable<UserModel, dynamic>(sql, new { }, _config.GetConnectionString("default"));
    selectedEmployees = new List<UserModel>() { users.FirstOrDefault() };
}

public async Task CreateUser()
{
    UserModel newUser = await DialogService.OpenAsync<DialogCreateUser>("Create a new user", null, new DialogOptions() { Width = "900px", Height = "512px", Resizable = true, Draggable = true });

    if (newUser != null)
    {
        await RefreshGrid();

        NotificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Success, Summary = "New user", Detail = newUser.userFirstname + " " + newUser.userLastname + " succesfully created", Duration = 6000, Style = "position: fixed; top: 90%; right: 1%; transform: translate(0%, 0%);", });
    }

}

private async Task RefreshGrid()
{
    string sql = "select * from users";
    users = await _data.LoadDataIEnumerable<UserModel, dynamic>(sql, new { }, _config.GetConnectionString("default"));

    await grid.Reload();

    StateHasChanged();
}

private void EditUser(int userID)
{
    NotificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "Edit user clicked!", Detail = "Edit user is not yet supported" });
}

private async void DeleteUser(int userID)
{
    string selectedUsername = selectedEmployees[0].userFirstname + " " + selectedEmployees[0].userLastname;
    string sql = "delete from users where userID = @userID;";
    await _data.SaveData(sql, new { userID = userID }, _config.GetConnectionString("default"));

    await RefreshGrid();

    NotificationService.Notify(new NotificationMessage
        {
            Severity = NotificationSeverity.Error,
            Summary = "User deleted",
            Detail = selectedUsername + " was deleted succesfully",
            Style = "position: fixed; top: 90%; right: 1%; transform: translate(0%, 0%);",
            Duration = 6000
        });
}

}

Mainlayout.razor:
@inherits LayoutComponentBase

<RadzenHeader>
    <RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" Gap="0">
        <RadzenSidebarToggle Click="@(() => sidebar1Expanded = !sidebar1Expanded)" />
        <RadzenLabel Text="Header" />
    </RadzenStack>
</RadzenHeader>
<RadzenSidebar @bind-Expanded="@sidebar1Expanded">
    <RadzenPanelMenu>
        <RadzenPanelMenuItem Text="Home" Icon="home" Path="" />
        <RadzenPanelMenuItem Text="Planning" Icon="event" Path="planning" />
        <RadzenPanelMenuItem Text="Projects" Icon="work" Path="projects" />
        <RadzenPanelMenuItem Text="Users" Icon="group" Path="users" />
    </RadzenPanelMenu>
</RadzenSidebar>
<RadzenBody>
    <div class="rz-p-4">
        @Body
    </div>
</RadzenBody>

@code {
bool sidebar1Expanded = true;
}

Program.cs (not the client, but I've also tried this without succes)
builder.Services.AddRadzenComponents();
builder.Services.AddScoped();

Also tested without adding

Any tips?

I don’t see <RafzenComponents /> in your layout.

This is the MainLayour.razor:

@inherits LayoutComponentBase

<RadzenHeader>
    <RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" Gap="0">
        <RadzenSidebarToggle Click="@(() => sidebar1Expanded = !sidebar1Expanded)" />
        <RadzenLabel Text="Header" />
    </RadzenStack>
</RadzenHeader>
<RadzenSidebar @bind-Expanded="@sidebar1Expanded">
    <RadzenPanelMenu>
        <RadzenPanelMenuItem Text="Home" Icon="home" Path="" />
        <RadzenPanelMenuItem Text="Planning" Icon="event" Path="planning" />
        <RadzenPanelMenuItem Text="Projects" Icon="work" Path="projects" />
        <RadzenPanelMenuItem Text="Users" Icon="group" Path="users" />
    </RadzenPanelMenu>
</RadzenSidebar>
<RadzenBody>
    <div class="rz-p-4">
        @Body
    </div>
</RadzenBody>

@code {
bool sidebar1Expanded = true;
}

I also tried removing it from MainLayout and place it only on the user page, than it shows, but when clicking the "X" button to close, it jumps around the screen..

You don't seem to have followed the getting started instructions (namely the part about static rendering).

1 Like

I removed RadzenComponents from the MainLayout.razor and placed it on the actual user page, now it works. I did not know that SSR and Interactive Server were the same that's why I thought it was not applicable for this application, many thanks!

The dialog now opens, but typing in the textboxes is not possible

I have this exact same issue. I can put the <RadzenComponents @rendermode="InteractiveAuto"/> tag in MainLayout and everything works until an InteractiveAuto page (in the Client project) loads as a WebAssembly page - then the dialogs stop working on all the Server pages.
Removing the tag from MainLayout and adding to each page and changing the RenderMode causes the text boxes not to be able to be typed into. I'm assuming this is because it is now nested down inside the RadzenLayout structure which has "position: static" set on the header?

1 Like

Hi @nunile , have you been able to solve this issue at all?

Hello @jai11,

For now I switched the complete application to be Interactive Server, so no WebAssembly or InteractiveAuto functionality. It now all works. Later on I want to try to also get it working with InteractiveAuto

Take a look at the section "Apply a render mode to the entire app"

1 Like

You can easily check if the Interactive Server is working after making the required changes

  1. Load the desired page
  2. Press RMB > Inspect
  3. Look for the "Network" tab
  4. Look for the "WS" chip (Web sockets)
  5. Press F5 (reloads page)
  6. When WS chip is active, there should be 3 connections visible

Thank you, thats a shame though as I have some pages I need to work as "Auto" since they are used on a mobile device with poor cell coverage and I would like to get away from the dreaded "Reconnecting" message in Blazor Server.
Other pages are really only used on a PC so server mode is fine.
Trying to give the users the best of both worlds :slight_smile:
@korchev Would you happen to have a demo at all that shows the Dialog working in an app with some pages being Server Render and others being Auto (or WebAssembly)? Perhaps this is something that isnt supported yet?

I have a similar issue and cannot figure out how to resolve. I've followed the Getting Started and my entire app is set to @rendermode="@InteractiveServer". By the way, I've used nothing but Razden Blazor Studio to create my app. With in place at the top of my MainLayout.razor file, all my action events, such as double-clicking on a row and being navigated to a details page work. However, with this in place, any modal dialogs open with a double overlay as though the modal is being called twice. If I remove from MainLayout, then the double modal issue goes away and I get functioning modal behavior as I'd expect, however my row doubleclick events and whatnot no longer work.