Nested dialogs not working

Hi I have created a git repo to make it easier to reproduce the error I am getting.

This is what I am trying:
Call a custom dialog using await. From the dialog I need to show a confirm dialog if the user wants to deactivate the contact person.

When the user choose to deactivate the contact the confirm dialog closes and then I close the dialog, this does not return to the calling code.

On the Index page

 private async Task EditContactButtonClick()
    {
        var contactToEdit = new Contact();

        try
        {
            var objAsync = await DialogService.OpenAsync<ContactCreate>(
                "Edit Contact",
                new Dictionary<string, object> { { "Contact", contactToEdit } });

            if (!(objAsync is Contact contactToUpdate))
            {
                Notifications.Notify(NotificationSeverity.Info, "Dialog was cancelled ", duration: 10_000);
                return; // maybe canceled edit then objAsync has the value true
            }

            Notifications.Notify(NotificationSeverity.Success, $"Contact is {contactToUpdate.Active}", duration: 10_000);
        }
        catch (Exception e)
        {
            Notifications.Notify(NotificationSeverity.Error, "Unable to update the contact, " + e.Message);
        }
    }

In the code for the custom dialog

 public partial class ContactCreate
{
    [Inject]
    private DialogService DialogService { get; set; }

    [Parameter]
    public Contact Contact { get; set; } = new Contact();

    private async Task InactivateContactButtonClicked()
    {
        if (await DialogService.Confirm("Setting a contact inactive will also remove all reports for that contact. ", "Inactivate Contact?") == false)
        {
            return;
        }
        Contact.Active = false;
        DialogService.Close(Contact);
    }
    
    private void HandleValidSubmit()
    {
        DialogService.Close(Contact);
    }
}

The code in the InactivateContactButtonClicked waits for the confirm dialog and then closes itself DialogService.Close(Contact); But the calling procedure EditContactButtonClick are not called.

Same problem here

Thomas

@Thomas you have the same code? Will you post it? Even better - send us your app at info@radzen.com where we can reproduce the problem.

Hi @Martin-Andersen and @enchev,
i have cloned your git hub project and tested around a while.
This is my solution that works in your code and in mine:

public partial class ContactCreate
{
    [Inject]
    private DialogService DialogService { get; set; }

    [Parameter]
    public Contact Contact { get; set; } = new Contact();

    private async Task InactivateContactButtonClicked()
    {
        if (await DialogService.Confirm("Setting a contact inactive will also remove all reports for that contact. ", "Inactivate Contact?") == false)
        {
            return;
        }
        Contact.Active = false;
        here => "await Task.Delay(100);"
        DialogService.Close(Contact);
    }
    
    private void HandleValidSubmit()
    {
        DialogService.Close(Contact);
    }
}

Try await Task.Delay(100); (see above). Its some sort of timing problem in DialogService. If you close dialogs with DialogService.Close() to fast after another some close events are not processed.
In my case a taskdelay of 10 ms ist enough to get this to work. The taskdelay must be used from the second dialog which is closed. In the "highest" dialog close works fine (for sure). But from there on you must use taskdelay.
Clear.. this is only a workaround.
I hope the radzen team finds a solution for this :slight_smile:

@enchev do you need a project for clearance?

1 Like

Hi Thomas thanks for the solution. Easy to implement but as you said, a fix. again thanks

Hello Radzen Team,
can you please fix this problem?

Kind Regards
Thomas

@Thomas you haven't answered @enchev 's question ... Requesting support on behalf of other users who are not customers isn't something that we encourage.

Hi @korchev,
sorry. I will send a project as soon as possible :wink:

Thomas