# Nested dialogs not working

**URL:** <https://forum.radzen.com/t/nested-dialogs-not-working/6135>\
**Category:** Radzen.Blazor Components\
**Created:** [December 29, 2020, 10:23am UTC](https://forum.radzen.com/t/nested-dialogs-not-working/6135 "2020-12-29T10:23:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin-Andersen](https://forum.radzen.com/user_avatar/forum.radzen.com/martin-andersen/32/4492_2.png) [@Martin-Andersen](https://forum.radzen.com/u/Martin-Andersen)\
**Post date:** [December 29, 2020, 10:23am UTC](https://forum.radzen.com/t/nested-dialogs-not-working/6135/1 "2020-12-29T10:23:58Z")

</div>

Hi I have created [a git repo](https://github.com/Martin-Andersen/RadzenNestedDialog) 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.

---

<div class="post-metadata">

**Author:** ![Thomas](https://forum.radzen.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@Thomas](https://forum.radzen.com/u/Thomas)\
**Post date:** [December 29, 2020, 2:31pm UTC](https://forum.radzen.com/t/nested-dialogs-not-working/6135/2 "2020-12-29T14:31:23Z")

</div>

Same problem here

Thomas

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [December 29, 2020, 2:37pm UTC](https://forum.radzen.com/t/nested-dialogs-not-working/6135/3 "2020-12-29T14:37:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thomas](https://forum.radzen.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@Thomas](https://forum.radzen.com/u/Thomas)\
**Post date:** [January 22, 2021, 7:51pm UTC](https://forum.radzen.com/t/nested-dialogs-not-working/6135/4 "2021-01-22T19:51:52Z")

</div>

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 🙂

@enchev do you need a project for clearance?

---

<div class="post-metadata">

**Author:** ![Martin-Andersen](https://forum.radzen.com/user_avatar/forum.radzen.com/martin-andersen/32/4492_2.png) [@Martin-Andersen](https://forum.radzen.com/u/Martin-Andersen)\
**Post date:** [January 22, 2021, 8:24pm UTC](https://forum.radzen.com/t/nested-dialogs-not-working/6135/5 "2021-01-22T20:24:05Z")

</div>

> [@Thomas](#):
>
> @enchev do you need a project for clearance?

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

---

<div class="post-metadata">

**Author:** ![Thomas](https://forum.radzen.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@Thomas](https://forum.radzen.com/u/Thomas)\
**Post date:** [January 25, 2021, 12:04pm UTC](https://forum.radzen.com/t/nested-dialogs-not-working/6135/6 "2021-01-25T12:04:07Z")

</div>

Hello Radzen Team,  
can you please fix this problem?

Kind Regards  
Thomas

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [January 25, 2021, 12:22pm UTC](https://forum.radzen.com/t/nested-dialogs-not-working/6135/7 "2021-01-25T12:22:30Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Thomas](https://forum.radzen.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@Thomas](https://forum.radzen.com/u/Thomas)\
**Post date:** [January 25, 2021, 12:54pm UTC](https://forum.radzen.com/t/nested-dialogs-not-working/6135/8 "2021-01-25T12:54:06Z")

</div>

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

Thomas
