I'm currently creating a Blazor Server app.
The component used here is Radzen Blazor.
I want to display a dialog box when I display the page (like entering a password, for example) and receive the result.
I thought this password verification should be done first, so I wrote the code inside OnInitializedAsync () to display a dialog box.
However, I am using await in the "await DialogService.OpenAsync (messageTitle, dParam, dOpt);" part of the "Code that calls the dialog box" code below, but the dialog box is not displayed and the code is I will move on.
When I call the dialog box somewhere other than OnInitializedAsync () for validation (eg when I press a button), await works and the dialog box is displayed.
I may not understand the behavior of asynchronous processing and OnInitializedAsync, but why doesn't the asynchronous processing await called inside OnInitializedAsync () work?
---Code that uses dialog boxes---
protected override async Task OnInitializedAsync()
{
var passCheck = await base.PasswordDialogBox("Please enter your password", "Password");
if (passCheck)
{
//What to do if the password is correct
}
}
---Code that calls the dialog box---
protected async Task<bool> PasswordDialogBox(string messageText, string messageTitle)
{
var dParam = new Dictionary<string, object>() { { "Message", messageText } };
var dOpt = new Radzen.DialogOptions() { Width = "500px", Height = "300px" };
// ↓not stop
var passCheck = await DialogService.OpenAsync<PasswordDialog>(messageTitle, dParam, dOpt);
if(passCheck == null)
{
passCheck = false;
}
return passCheck;
}