A Blazor Wrapper for JS's Window.confirm() and onbeforeunload as .Net Blazor Component.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE Update issue templates Oct 28, 2018
ScreenShots initial push Oct 23, 2018
docs Update index.html Nov 16, 2018
src migrated to Blazor 0.7.0 Nov 16, 2018
.gitignore onbeforeunload added Oct 24, 2018
BlazorConfirm.sln initial push Oct 23, 2018
LICENSE Initial commit Oct 23, 2018
README.md Merge branch 'master' of github.com:ctrl-alt-d/BlazorConfirm Nov 16, 2018



Blazor Confirm Dialog | Blazor Confirm Close Tab

A Blazor wrapper of Window.confirm() and onbeforeunload confirmation as .Net Blazor Component.

The sample project has been published here.

Note: Just as Blazor, this repo is also experimental.

Why confirm?


Avoid using dialog boxes for confirmation.

... but in some cases we need them.

ScreenShot and Demo

Because we love screen shots and demos.

Demo: https://ctrl-alt-d.github.io/BlazorConfirm/

BlazorConfig ScreenShot



    • Migrated to Blazor 0.7.0 experimental.

    • Handling onbeforeunload
  • version 0.6.0

    • initial version for blazor 0.6.0


dotnet add package BlazorConfirm --version


Install-Package BlazorConfirm -Version

Configure the dependency injection

Set DI on ConfigureServices of your Startup.cs:

using ctrlaltd.SimpleBlazorComponents;
using Microsoft.AspNetCore.Blazor.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace Sample
    public class Startup
        public void ConfigureServices(IServiceCollection services)
            services.AddSingleton<IBlazorConfirmDialog, BlazorConfirmDialog>(); //Add as singleton.

and add the component to App.cshtml (or to another component always loaded in the application)

@addTagHelper *, BlazorConfirm
<BlazorConfirmContainer />

<Router AppAssembly=typeof(Program).Assembly />


In a component:

@inject ctrlaltd.SimpleBlazorComponents.IBlazorConfirmDialog blazorConfirmDialog

In a class:

protected ctrlaltd.SimpleBlazorComponents.IBlazorConfirmDialog blazorConfirmDialog { get; set; }

At this point you can wrap your code into the onSuccessDelegate Dialog:

void IncrementCount()
    blazorConfirmDialog.NewDialog( message: "Are you sure do you want to increment the counter?", 
                                   onSuccessDelegate: ( () => {currentCount++;
                                                               } ) );

A sample to confirm exit current page:

blazorConfirmDialog.NewDialog( onSuccessDelegate: (() => {UriHelper.NavigateTo(  "/fetchdata" );}));


Dani Herrera


BlazorConfirm is licensed under MIT license

Special Thanks

Thankyou to @ghidello and https://github.com/sotsera/sotsera.blazor.toaster repo.