DialogService OnClose getting called unexpectedly

See below code snippet. I implemented override OnInitialized() as suggested in your samples project. However, my Close() method was being called during navigation to/from this page, regardless if the dialog was ever shown or not.

As you can see below, I commented this out, and implemented the DialogService.OnClolse +/- all within one method that actually opens the dialog - and this seems to work fine ... so I seem to have worked around this OR is this the preferred way anyhow?

In any case, please note this as perhaps you have a bug: the OnClose event handler should not be getting called if the dialog was never opened.

From "LoginComponent.razor":

[Inject]
DialogService DialogService { get; set; }

//protected override void OnInitialized()
//{
//    DialogService.OnClose -= Close;
//    DialogService.OnClose += Close;
//}

AppUser AppUser { get; set; }

async Task ShowRegistrationDialog()
{
    DialogService.OnClose -= Close;
    DialogService.OnClose += Close;

    AppUser = new AppUser("Registration");
    await DialogService.OpenAsync(Resources.Register, ds => @<RegistrationComponent AppUser="@AppUser"/>);

    DialogService.OnClose -= Close;
}

[Inject]
IStorage Storage { get; set; }

void Close(dynamic result)
{
    Storage.AddRange(new Data[] { AppUser });
}
1 Like

Thanks! It will be fixed in the next update.

1 Like

Can dialog.Close passing more than 1 parameter ? Like code below .

dialog.OnClose += DelegateOnClose;

void DelegateOnClose(dynamic result){ ...do something }

<RadzenButton Click="@(()=>ds.Close(parm1,...paramN)    )">

If it can. Please share me example code

You can use a C# tuple type or a class for the result and achieve the same effect - multiple values.

ds.Close((param1, param2))