Skip to main content

Blazor Radio Input

The Blazor Bootstrap RadioInput component is built on an HTML input of type radio, with a disabled state, Enable and Disable methods and a ValueChanged event.

Blazor Bootstrap: Radio Input Component

Parameters​

NameTypeDefaultRequiredDescriptionAdded Version
DisabledboolfalseGets or sets the disabled state.3.3.0
LabelstringnullGets or sets the label.3.3.0
NamestringnullGets or sets the name.3.3.0
Valueboolfalse✔️Gets or sets the value.3.3.0

Methods​

NameReturnsDescriptionAdded Version
Disable()voidDisables autocomplete.3.3.0
Enable()voidEnables autocomplete.3.3.0

Events​

NameDescriptionAdded Version
ValueChangedThis event fires when the RadioInput value changes.3.3.0

Examples​

Basic Usage​

Blazor Bootstrap Radio Input Component - Basic Usage
<p>Would you like to receive notifications?</p>
<RadioInput Name="EnableNotifications" Label="Yes" @bind-Value="isYesOn" />
<RadioInput Name="EnableNotifications" Label="No" @bind-Value="isNoOn" />

<div class="mt-3">
<div>IsYesOn: @isYesOn</div>
<div>IsNoOn: @isNoOn</div>
</div>
@code
{
private bool isYesOn;
private bool isNoOn = true;
}

See demo here

Disable​

Use the Disabled parameter to disable the RadioInput.

Blazor Bootstrap Radio Input Component - Disable
<p>Would you like to receive notifications?</p>
<RadioInput Name="EnableNotifications" Label="Yes" @bind-Value="isChecked" Disabled="disabled" />
<RadioInput Name="EnableNotifications" Label="No" @bind-Value="isChecked2" Disabled="disabled" />

<div class="mt-3">
<Button Color="ButtonColor.Primary" Size="ButtonSize.ExtraSmall" @onclick="Enable"> Enable </Button>
<Button Color="ButtonColor.Secondary" Size="ButtonSize.ExtraSmall" @onclick="Disable"> Disable </Button>
<Button Color="ButtonColor.Warning" Size="ButtonSize.ExtraSmall" @onclick="Toggle"> Toggle </Button>
</div>
@code
{
private bool isChecked;
private bool isChecked2 = true;

private bool disabled = true;

private void Enable() => disabled = false;

private void Disable() => disabled = true;

private void Toggle() => disabled = !disabled;
}

Also, use Enable() and Disable() methods to enable and disable the RadioInput.

NOTE

Do not use both the Disabled parameter and Enable() & Disable() methods.

<p>Would you like to receive notifications?</p>
<RadioInput @ref="radioInputRef" Name="EnableNotifications" Label="Yes" @bind-Value="isChecked" />
<RadioInput @ref="radioInputRef2" Name="EnableNotifications" Label="No" @bind-Value="isChecked2" />

<div class="mt-3">
<Button Color="ButtonColor.Primary" Size="ButtonSize.ExtraSmall" @onclick="Enable"> Enable </Button>
<Button Color="ButtonColor.Secondary" Size="ButtonSize.ExtraSmall" @onclick="Disable"> Disable </Button>
</div>
@code
{
private RadioInput? radioInputRef;
private RadioInput? radioInputRef2;

private bool isChecked;
private bool isChecked2 = true;

private void Disable()
{
radioInputRef.Disable();
radioInputRef2.Disable();
}

private void Enable()
{
radioInputRef.Enable();
radioInputRef2.Enable();
}
}

See demo here

More libraries from the team

Free, open-source .NET libraries built by the same team.

UnlimitedPDF

A pure .NET library to create, merge and split PDFs, and convert HTML to PDF.

BlazorExpress.ChartJS

Chart.js charts for Blazor, configured in C#.

BlazorExpress.Bulma

Enterprise-class Blazor components built on the Bulma CSS framework.