Open Dialog on onload of a page

Is it possible that if I load the Index.razor page of my webapp that when a certain condition is true (database is empty) that I start a dialog with some textboxes et cetera?

Yes, you can use the DialogService in the OnInitialized method of your page.

1 Like

Hey Korchev, thanx for the fix! OpenAsync of a dialog doesn't seem to work in the oninitializedasync method of the page... It only works when the onititialized method is not async. Pretty weird huh?

You can then try OnAfterRenderAsync. We will investigate why it doesn't work in OnInitializedAsync.

protected override async Task OnAfterRenderAsync(bool firstRender)
{
   if (firstRender)
   {
       await DialogService.OpenAsync<DialogCardPage>($"Order {orderID}",
          new Dictionary<string, object>() { { "OrderID", orderID } },
          new DialogOptions { Width = "700px", Height = "530px" }
       );
   }
} 
1 Like

This works even better than the non-async way! Thank you so much!