IDialogService

The IDialogService provides methods for displaying modal dialogs to the user, including confirmation prompts, error messages, informational notices, success notifications, and warnings.

Injecting the Service

Access the dialog service from any component. In React call useDialogService() from inside the tree wrapped by the framework dialog provider; in Blazor inject the service via property injection. Note that the PowerPortalsPro dialog service is distinct from the underlying FluentUI dialog service.

React Blazor

Confirmation Dialogs

Use ShowConfirmationAsync to prompt the user with a yes/no question. The returned DialogResult.Cancelled property is true when the user selects the secondary (negative) option.

React Blazor

Message Dialogs

Use the following methods to show single-button message dialogs with different visual styles:

  • ShowInfoAsync — Informational message with a neutral icon.
  • ShowSuccessAsync — Success message with a green checkmark icon.
  • ShowWarningAsync — Warning message with a yellow warning icon.
  • ShowErrorAsync — Error message with a red error icon.
React Blazor

Dialogs With Your Own Content

ShowDialogAsync shows content of your own, such as a form, a picker or a preview, and returns what the dialog closes with. In Blazor, pass a component (or a RenderFragment); in React, pass a function that renders the content. Set PrimaryText and SecondaryText for buttons the service draws, or leave both out for content that draws its own.

The content is given the dialog it is shown in: an IDialogContext in Blazor, received as a cascading parameter, and a DialogHandle in React, passed to the render function and available anywhere inside through useDialogHandle(). Use it to close with a value, cancel, enable or disable the primary button, or set what the primary button does. What that action returns is what the dialog returns. Return KeepOpen (KEEP_OPEN in React) to keep the dialog open, for example while the input isn't valid yet.

React Blazor

Custom Content Demo

Opens a dialog with a form. Save keeps the dialog open until a name is entered, then returns it to the page; Cancel returns nothing.

React example Blazor example React TypeScript Razor
Rename…

Common Parameters

All dialog methods accept optional title and primaryText parameters. If omitted, localized default values are used. The confirmation dialog also accepts a secondaryText parameter for the cancel button label.

Dialog Result

All methods return a DialogResult object. For confirmation dialogs, check the Cancelled property to determine the user's choice. For message dialogs, the result indicates the dialog was dismissed.

Interactive Demo

Use the controls below to customize the dialog title and message, then click any button to see the corresponding dialog type.

React example Blazor example React TypeScript Razor
Show Confirmation Dialog Show Error Dialog Show Info Dialog Show Success Dialog Show Warning Dialog
React Blazor

IDialogService Interface

Properties

Name
Type
Default
Description
OpenDialogCountint
How many dialogs this service currently has open. Its own dialogs only — the message boxes and confirmations raised through the methods below. A record panel is a FluentUI dialog raised through their service, so it is not counted here, and that is what makes this number useful to the overlay layer: it means 'a message the user has to be able to read and answer', not 'something dialog-shaped is open'.
Name: OpenDialogCount
Type: int
Description: How many dialogs this service currently has open. Its own dialogs only — the message boxes and confirmations raised through the methods below. A record panel is a FluentUI dialog raised through their service, so it is not counted here, and that is what makes this number useful to the overlay layer: it means 'a message the user has to be able to read and answer', not 'something dialog-shaped is open'.

Methods

Name
Parameters
Type
Description
ShowConfirmationAsyncstring message
string title
string primaryText
string secondaryText
Task<DialogResult>
Shows a confirmation dialog with the supplied message and two action buttons, then waits for the user to choose one. The returned Services.DialogResult has DialogResult.Cancelled set to true when the user selects the secondary (negative) option.
ShowDialogAsync<TComponent>Action<CustomDialogOptions> configure
IDictionary<string, Object> parameters
Task<DialogResult>
Shows in a dialog and waits for it to close.
ShowErrorAsyncstring message
string title
string primaryText
Task<DialogResult>
Shows an error dialog with the supplied message and waits for the user to dismiss it.
ShowInfoAsyncstring message
string title
string primaryText
Task<DialogResult>
Shows an informational dialog with the supplied message and waits for the user to dismiss it.
ShowSuccessAsyncstring message
string title
string primaryText
Task<DialogResult>
Shows a success dialog with the supplied message and waits for the user to dismiss it.
ShowWarningAsyncstring message
string title
string primaryText
Task<DialogResult>
Shows a warning dialog with the supplied message and waits for the user to dismiss it.
Name: ShowConfirmationAsync
Parameters: string message
string title
string primaryText
string secondaryText
Type: Task<DialogResult>
Description: Shows a confirmation dialog with the supplied message and two action buttons, then waits for the user to choose one. The returned Services.DialogResult has DialogResult.Cancelled set to true when the user selects the secondary (negative) option.
Name: ShowDialogAsync<TComponent>
Parameters: Action<CustomDialogOptions> configure
IDictionary<string, Object> parameters
Type: Task<DialogResult>
Description: Shows in a dialog and waits for it to close.
Name: ShowErrorAsync
Parameters: string message
string title
string primaryText
Type: Task<DialogResult>
Description: Shows an error dialog with the supplied message and waits for the user to dismiss it.
Name: ShowInfoAsync
Parameters: string message
string title
string primaryText
Type: Task<DialogResult>
Description: Shows an informational dialog with the supplied message and waits for the user to dismiss it.
Name: ShowSuccessAsync
Parameters: string message
string title
string primaryText
Type: Task<DialogResult>
Description: Shows a success dialog with the supplied message and waits for the user to dismiss it.
Name: ShowWarningAsync
Parameters: string message
string title
string primaryText
Type: Task<DialogResult>
Description: Shows a warning dialog with the supplied message and waits for the user to dismiss it.
React Blazor

DialogResult Class

Properties

Name
Type
Default
Description
Cancelledbool
False
Gets a value indicating whether the dialog was cancelled (e.g. the user dismissed it without confirming).
DataObject?
Optional data payload returned by the dialog when it was closed.
Name: Cancelled
Type: bool
Default: False
Description: Gets a value indicating whether the dialog was cancelled (e.g. the user dismissed it without confirming).
Name: Data
Type: Object?
Description: Optional data payload returned by the dialog when it was closed.

Methods

Name
Parameters
Type
Description
CancelObject data
DialogResult
Creates a Services.DialogResult representing a cancelled outcome, optionally carrying a data payload.
GetData<T>T?
The value the dialog closed with, as : default when it was cancelled, closed with nothing, or closed with a value of another type.
Ok<T>T result
DialogResult
Creates a Services.DialogResult representing a confirmed outcome, carrying result as the data payload.
TryGetData<T>out T value
bool
Reads the value the dialog closed with, as .
Name: Cancel
Parameters: Object data
Type: DialogResult
Description: Creates a Services.DialogResult representing a cancelled outcome, optionally carrying a data payload.
Name: GetData<T>
Type: T?
Description: The value the dialog closed with, as : default when it was cancelled, closed with nothing, or closed with a value of another type.
Name: Ok<T>
Parameters: T result
Type: DialogResult
Description: Creates a Services.DialogResult representing a confirmed outcome, carrying result as the data payload.
Name: TryGetData<T>
Parameters: out T value
Type: bool
Description: Reads the value the dialog closed with, as .
React Blazor

CustomDialogOptions Class

Properties

Name
Type
Default
Description
PreventDismissOnEscapebool
False
Whether Escape is kept from closing the dialog. Default false.
PrimaryTextstring?
The primary button's label. The service draws the button when this is set; leave both this and CustomDialogOptions.SecondaryText unset for content that draws its own buttons. What the button does is up to IDialogContext.OnPrimary.
SecondaryTextstring?
The secondary button's label. The service draws the button when this is set, and it cancels the dialog.
ShowDismissbool
True
Whether the header shows a close button. Default true.
Titlestring?
The dialog's title, shown in its header. Omit it for a dialog without one.
Widthstring?
The dialog's width as a CSS length, e.g. 'min(700px, 90vw)'. Omit it for the default.
Name: PreventDismissOnEscape
Type: bool
Default: False
Description: Whether Escape is kept from closing the dialog. Default false.
Name: PrimaryText
Type: string?
Description: The primary button's label. The service draws the button when this is set; leave both this and CustomDialogOptions.SecondaryText unset for content that draws its own buttons. What the button does is up to IDialogContext.OnPrimary.
Name: SecondaryText
Type: string?
Description: The secondary button's label. The service draws the button when this is set, and it cancels the dialog.
Name: ShowDismiss
Type: bool
Default: True
Description: Whether the header shows a close button. Default true.
Name: Title
Type: string?
Description: The dialog's title, shown in its header. Omit it for a dialog without one.
Name: Width
Type: string?
Description: The dialog's width as a CSS length, e.g. 'min(700px, 90vw)'. Omit it for the default.
React Blazor

IDialogContext Interface

Properties

Name
Type
Default
Description
OnPrimaryFunc<Task<Object>>?
Runs when the service-drawn primary button is pressed. Its result is what the dialog returns, in DialogResult.Data; return IDialogContext.KeepOpen to keep the dialog open instead. Unset, the button closes the dialog with no data. While it runs the buttons are disabled and Escape doesn't dismiss the dialog (on Blazor Server, from a moment after the click: the block reaches the browser a round trip later). If it throws, the error is logged, the dialog stays open, and a general error message is shown over it; for failures a user can fix, say what went wrong yourself and return IDialogContext.KeepOpen.
PrimaryEnabledbool
Whether the service-drawn primary button can be pressed, e.g. only once a required choice is made. Default true.
Name: OnPrimary
Type: Func<Task<Object>>?
Description: Runs when the service-drawn primary button is pressed. Its result is what the dialog returns, in DialogResult.Data; return IDialogContext.KeepOpen to keep the dialog open instead. Unset, the button closes the dialog with no data. While it runs the buttons are disabled and Escape doesn't dismiss the dialog (on Blazor Server, from a moment after the click: the block reaches the browser a round trip later). If it throws, the error is logged, the dialog stays open, and a general error message is shown over it; for failures a user can fix, say what went wrong yourself and return IDialogContext.KeepOpen.
Name: PrimaryEnabled
Type: bool
Description: Whether the service-drawn primary button can be pressed, e.g. only once a required choice is made. Default true.

Methods

Name
Parameters
Type
Description
CancelAsyncTask
Closes the dialog as cancelled, which returns Cancel(System.Object).
CloseAsyncObject data
Task
Closes the dialog, which returns DialogResult.Ok`<T>(`<U>) with data.
Name: CancelAsync
Type: Task
Description: Closes the dialog as cancelled, which returns Cancel(System.Object).
Name: CloseAsync
Parameters: Object data
Type: Task
Description: Closes the dialog, which returns DialogResult.Ok`<T>(`<U>) with data.