[SOLVED] Radzen Blazor server side: problem with DialogService and delegates

Hello everyone.
I have the following server-side Blazor application with 2 pages with 2 grids from 2 different tables in a database.

Every row in the table has an edit button which executes a RadzenDialog and in every radzen page I have on method OnInitialized the delegates for Open and Close for the dialog like this:

    DialogService.OnOpen += MyOpen;
    DialogService.OnClose += MyClose;

for every page.

The problem is:
When I go to page 2, do nothing or do an edit, and then go to page 1, insead of the methods from page 1, are executed the methods from page 2 and I've noticed when I go for a third time on the second page the events are fired twice!

How can I fix this problem?

Thank you

Hi @LuciferSam,

You need to remove the event handlers of the dialog service. This can be done by making your pages implement IDisposable:

public void Dispose
{
    DialogService.OnOpen -= MyOpen;
    DialogService.OnClose -= MyClose;
}

Also you may not need to use OnOpen and OnClose altogether. The OpenAsync method of the dialog service returns the result used when the dialog service is closed.

var result = await DialogService.OpenAsync<MyDialog>();

and then in MyDialog.razor

var dialogResult = true;
DialogService.Close(dialogResult);

It worked like a charm.
Thank you!

(if it's needed it's possible to close the thread)