---
title: "Confirmation dialog and toast in C#"
url: https://recursiveai.org/oneapp/cookbook/show-dialog-and-toast-with-ui-kit/
description: "Ask for confirmation with OneApp’s AlertDialog, then show a success toast only after the user confirms. Run the complete .NET 10 desktop example."
version: "1.0.0"
---

`AlertDialog` asks the user to confirm; `Toast.Success` reports the result inside the window.

```shell
dotnet add package RecursiveAI.OneApp.Kit
dotnet add package RecursiveAI.OneApp
dotnet add package RecursiveAI.OneUI
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```html
<AlertDialog Id="archive" Open="{Open}"
             OnOpenChange="{v => Open = v}">
  <template slot="trigger">
    <Button Id="ask">Archive note</Button>
  </template>
  <DialogFooter>
    <Button Id="cancel" OnClick="{() => Open = false}">Cancel</Button>
    <Button Id="confirm" OnClick="{Archive}">Archive</Button>
  </DialogFooter>
</AlertDialog>
<Toaster />
```

[The example](https://recursiveai.org/oneapp/cookbook/show-dialog-and-toast-with-ui-kit/show-dialog-and-toast-with-ui-kit.zip) is the full program below: unzip it and `dotnet run`.

The snippet shows the connection points in `ConfirmPage.html`: the `Open` state, the `Archive` handler that sends the toast, and a `Toaster` that stays mounted. In the complete app, click **Archive note**, then **Archive** in the dialog. The window shows **Archived** and the toast **Note archived**. **Cancel** closes the dialog without changing the note or showing a toast.

## Full program

Place the three files below beside the .NET 10 console project. The OneUI markup compiler generates the other half of `ConfirmPage`, including the implementations of its `[State]` properties.

`ConfirmPage.html`:

```html
@using OneApp.Kit
<Theme>
  <main style="padding: 24px">
    <AlertDialog Id="archive" Open="{Open}"
                 OnOpenChange="{v => Open = v}">
      <template slot="trigger">
        <Button Id="ask">Archive note</Button>
      </template>
      <DialogHeader>
        <DialogTitle DialogId="archive">Archive this note?</DialogTitle>
        <DialogDescription DialogId="archive">
          This demo only changes the status in this window.
        </DialogDescription>
      </DialogHeader>
      <DialogFooter>
        <Button Id="cancel" OnClick="{() => Open = false}">Cancel</Button>
        <Button Id="confirm" OnClick="{Archive}">Archive</Button>
      </DialogFooter>
    </AlertDialog>
    <p id="status">{Status}</p>
    <Toaster />
  </main>
</Theme>
```

`ConfirmPage.cs`:

```csharp
using OneApp.Kit;
using OneUI.Components;

public partial class ConfirmPage
{
    [State] private partial bool Open { get; set; }
    [State] private partial string Status { get; set; }

    protected override void OnMounted() => Status = "Active";

    private void Archive()
    {
        Status = "Archived";
        Open = false;
        Toast.Success("Note archived");
        Console.WriteLine(Status);
    }
}
```

`Program.cs`, which mounts the component in a window:

```csharp
using OneApp;

using var host = AppHost.Create(new AppOptions(new ConfirmPage())
{
    Title = "ConfirmDemo",
    Width = 520,
    Height = 360,
});
host.Run();
```

Confirming prints this in the terminal:

```text
Archived
```

![The Archive this note confirmation with Cancel and Archive buttons](https://recursiveai.org/oneapp/images/show-dialog-and-toast-with-ui-kit/dialog.png)

![The window after confirmation, with the Archived status and Note archived toast](https://recursiveai.org/oneapp/images/show-dialog-and-toast-with-ui-kit/toast.png)

If the toast doesn’t appear, check that a `Toaster` is mounted outside the dialog so it remains on screen when `Open` becomes `false`.

## Variations

Use a local message stack instead of the shared default. Bind the `Toaster` to `Messages`, then send the message through that same model:

```html
<Toaster Model="{Messages}" />
```

```csharp
public ToastModel Messages { get; } = new();
```

Replace the call to `Toast.Success` inside `Archive`:

```csharp
Messages.Show("Note archived");
```

## Related recipes

- [Customize desktop dark mode and colors](https://recursiveai.org/oneapp/cookbook/theme-desktop-ui-kit/)
- [Package a C# desktop app for Linux](https://recursiveai.org/oneapp/cookbook/package-dotnet-desktop-app-for-linux/)

## The short answer

Use an `AlertDialog` for the decision and a `Toaster` for the result. Keep the open state in a C# `[State]` property. The trigger opens the dialog through `OnOpenChange`; Cancel only clears the open state. In the confirm handler, change the data, close the dialog, and call `Toast.Success`. The example changes a status in memory, not a file or database.

## How do I show a confirmation dialog in a C# desktop app?

Put the button that *opens* the dialog in its `trigger` slot. Put the decision buttons and a clear statement of the effect in the dialog itself. Match `DialogTitle.DialogId` and `DialogDescription.DialogId` to the dialog’s `Id`. That links the rendered dialog to its accessible name and description. Prefer explicit button labels such as **Archive** and **Cancel** so the user doesn’t have to interpret **Yes** and **No**.

`AlertDialog` is drawn inside the existing window. Unlike the kit’s regular `Dialog`, it has no close button and clicking the backdrop doesn’t dismiss it. Escape still dismisses it. The kit moves focus inside on open, wraps Tab and Shift+Tab inside the dialog, and returns focus to the trigger on close. For an irreversible action, use the `InitialFocus` parameter to focus the least destructive option.

## What’s a toast notification, and when should I use one?

In this app, a toast is feedback, not a question. It appears after the confirmation handler completes and doesn’t require a second acknowledgment. The kit’s `Toaster` uses an `aria-live="polite"` region and each message has `role="status"`. Keep the enduring result visible elsewhere too: the example leaves **Archived** next to the trigger even after the toast disappears.

`Toast.Success` targets `ToastModel.Default`. That’s why a plain `<Toaster />` receives it, and why switching to a local model means writing to that model instead. Keep the success toast on the success path; if a real archive operation fails, don’t show **Note archived**. The [kit overlay reference](https://recursiveai.org/oneapp/docs/kit/#overlays) lists the dialog parameters and toast variants.
