Nested Dialogs firing OnClose event

Hello Radzen Team!

I have this action hooked to the OnClose event on the Load method in my first dialog:

DialogService.OnClose += (Action<dynamic>) async delegate { await JSRuntime.InvokeVoidAsync("stop"); };

However this applies to the top most dialog. For example, if I open another dialog from my first one, then closes it, the event is triggered too.

So how can I subscribe to the dialog events of only the current dialog?

Hi @kim,

The DialogService controls all dialogs and this is why its events fire for all dialogs. If you want to execute code after a specific dialog is closed you can use the Then event of the Open dialog action in Radzen.

Did you mean something like this?

This will not work either, same results of the previous option.

As soon as a new dialog is opened from another dialog, the result of the first dialog is returned and Then code is executed.

I am afraid I don't understand what the problem is. We will need a reproduction. Please send it to info@radzen.com

I'm sorry, but I can't ship the app to your email at this point in development. I'll do my best to explain the problem below:

I have this method attached to the Click event of my button, to open the first dialog:

This is debugging step 1:

Next the first dialog opens:

Then in this first dialog I'll open a second dialog:

Right after closing the second dialog, the debugging hits step 2, which is very weird since my first dialog hasn't been submitted neither closed:

Then it executes the Then code even tough the first dialog is still open:


Tell me if you need more info on this problem.

Reproduced the issue and will investigate what is causing it.

1 Like

@kim I wonder if an @key directive could be used somehow.

Also, could this be related? DialogService OnClose getting called unexpectedly

Stephen

Hey @SloSuenos!

Maybe every dialog is missing its @key as you mentioned, because I think this was working before.

And that topic is definitely related to this problem, silly me for not noticing at first.

1 Like

I just deleted a previous loooong post here ... because ... I got multiple dialogs to work, as follows:

I initially did not notice that DialogService.OpenAsync returns the result - SO, there is no need for OnClose event handlers ... you can just continue working on the result after the awaited call returns.

Once I eliminated the OnClose event handlers all together, nested dialogs seem to work fine?

So it appears to me that DialogService.Close(...) just closes the top-most dialog, while the underlying one remains open and ok.

Thus, regarding:
[korchev]
Hi @kim,
The DialogService controls all dialogs and this is why its events fire for all dialogs. If you want to execute code after a specific dialog is closed you can use the Then event of the Open dialog action in Radzen.

Perhaps we can get by without any event handlers, i.e. if you want to execute code after a specific dialog closes, the you await the call to open it and assign the result in the same call, and then continue to execute in the same method ... works for me, am I missing anything?

2 Likes

Has this problem been addressed in the last version 2.54.6?

After updating it's still happening as shown above.

Hi @kim,

We've not managed to fix this in our latest build, sorry! I'll will do my best to send you our latest build tomorrow.

UPDATE: You can add empty Then to inner dialog open to fix it:

1 Like

Thanks for the updated suggestion, it is working now.