Dialog.OpenSideAsync doesn't fire

Background: I'm converting an MAUI app into a Blazor server app that uses the Scheduler component. I had added a simple login page to be called from the Index.OnInitialized. Works in MAUI. Doesn't work in web app. Everything else does with no change to the calling statement.

Here is the OnInit

protected override void OnInitialized()
{
if (String.IsNullOrEmpty(LogID) || (LogID == "Admin"))
{
Console.WriteLine("LoginID = " + LogID); //this does show in the console window
Console.WriteLine("Need to Log in"); //as does this

  string UID = "";
  LoginUser(UID);

}
reservations = ReservationService.GetExistingReservations();

}

And here is the calling proc:

async Task LoginUser(string UID)
{
Console.WriteLine("In LoginUser"); //again, show in Console window
LoginCreds user = await DialogService.OpenSideAsync("Log In",
new Dictionary<string, object>, new SideDialogOptions{Position = DialogPosition.Right});
UID = user.UserID;
LogID = UID;
}

Again: this works in the MAUI app.
All the other Dialog.CallAsync calls work, this one does not. Is there something different in the OpenSide dialog between MAUI and Blazor server?

As far as I am aware, the OpenSideAsync method expects an generic type which is the custom component that you want to load. Here's an example from the Radzen demo site.

async Task OpenSideDialog()
{
    await DialogService.OpenSideAsync<DialogSideContent>("Side Panel", options: new SideDialogOptions { CloseDialogOnOverlayClick = closeDialogOnOverlayClick, Position = position, ShowMask = showMask });
}

Looks like something got lost in the block copy/paste.

    LoginCreds user = await DialogService.OpenSideAsync<LoginPage>("Log In",
          new Dictionary<string, object>(), new SideDialogOptions{Position = DialogPosition.Right});

is the line that should be there.

Just out of curiosity if the normal OpenAsync dialog service is working for you? If that also doesn't work, make sure that you include the RadzenDialog tag somewhere in your markup which normally can be placed in the MainLayout.razor page. Also make sure it's registered in the DI container in the program.cs and inject the DialogService into the page.

Yes, the normal OpenAsync is working. The only thing that didn't make the translation from the working MAUI app is the OpenSideAsync

[quote="DBeaird, post:3, topic:15057"]




That's interesting. How about changing the assignment to the following.

var result = await DialogService.OpenSideAsync<LoginPage>("Log In",
          new Dictionary<string, object>(), new SideDialogOptions{Position = DialogPosition.Right});

//Cast it to the correct type
if (user is not null)
var user = (LoginCreds)result;

No change in behavior. Goes into the method, but doesn't run that line of code

Just read more closely in your initial post. It appears that you are not awaiting your async method.

Change LoginUser(UID) to await LoginUser(UID) should work.

"the 'await' command can only be used within an async method."

So, making the oninit call "async protected override void OnInitialized()", the blank calendar comes up, nothing else - so it's not running the Login, it's also not running the "GetExistingReservations".

Still enters the LoginUser method - just doesn't run the OpenSideAsync - or anything after.

it

It should be like this though.

protected async override Task OnInitializedAsync()
{

}

This version displays nothing.

Try this.

protected async override Task OnInitializedAsync()
{
if (String.IsNullOrEmpty(LogID) || (LogID == "Admin"))
{

	 string UID = "";
	 await LoginUser(UID);

}

reservations = ReservationService.GetExistingReservations(); //Not sure if this is also a async method. If so, also await it.

}

async Task LoginUser(string UID)
{

var result = await DialogService.OpenSideAsync<LoginPage>("Log In",
      new Dictionary<string, object>(), new SideDialogOptions{Position = DialogPosition.Right});

if (user is  null)
	return;
	
var user = (LoginCreds)result;

UID = user.UserID;
LogID = UID;

}

Still nothing. says "About:blank" in the addy bar.

I made an typo in the previous post. The null check should be if(result is null). Anyway, that shouldn't affect the side dialog from showing. Can you remove some logics and just test the dialog service but calling it from the OnAfterRenderAsync lifecycle event as rendering UI component should not be placed inside the OnInitializedAsync event.

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
string UID = "";
await LoginUser(UID);
}
}

async Task LoginUser(string UID)
{

var result = await DialogService.OpenSideAsync<LoginPage>("Log In",
      new Dictionary<string, object>(), new SideDialogOptions{Position = DialogPosition.Right});

}

That works. So my problem was trying to run a page from the wrong method. Alrighty then, I can work with that.
Thanks for the assistance. have a good one

I am glad that works. Yes. In Blazor, it's crucial to follow its lifecycle events to do certain things such as interacting with the UI. For example, calling JavaScript interop in the OnInitialized event is not recommended as the DOM is not ready until OnAfterRenderAsync first render.