New to Telerik UI for Blazor? Download free 30-day trial

Events

This article explains the events available in the Telerik RadioGroup for Blazor:

The examples in this article use string values and simple data sources for brevity. You can use full models, see the data binding article for more details.

OnChange

The OnChange event represents a user action - confirmation of the current value. In inputs, it fires when the user presses Enter in the input, or when the input loses focus. In the RadioGroup, it fires when the user selects an item because there is no other action.

The OnChange event is a custom event and does not interfere with bindings, so you can use it together with models and forms.

Handle the OnChange event and use two-way binding

@SelectedValue
<br />
<TelerikRadioGroup Data="@Data" @bind-Value="@SelectedValue" OnChange="@OnChangeHandler"></TelerikRadioGroup>
@code{
    string SelectedValue { get; set; }
    IEnumerable<string> Data { get; set; } = new List<string> { "first", "second", "third" };

    async Task OnChangeHandler(object  newValue)
    {
        // the handler receives an object that you may need to cast to the type of the component
        // if you do not provide a Value, you must provide the Type parameter to the component
        Console.WriteLine($"ValueChanged fired with value: {newValue as string}");
    }
}

The event is an EventCallback and it can be synchronous (return void), or it can also be asynchronous and return async Task.

ValueChanged

The ValueChanged event fires upon every change of the user selection.

The example below uses binding to primitive types for brevity, you can use full models as well.

Handle ValueChanged

@SelectedValue
<br />
<TelerikRadioGroup Data="@Data" Value="@SelectedValue" ValueChanged="@( (string v) => ValueChangedHandler(v) )"></TelerikRadioGroup>
@code{
    string SelectedValue { get; set; }
    IEnumerable<string> Data { get; set; } = new List<string> { "first", "second", "third" };

    void ValueChangedHandler(string newValue)
    {
        SelectedValue = newValue;
        //you have to update the model manually because handling the ValueChanged event does not let you use @bind-Value
        Console.WriteLine($"ValueChanged fired with value: {newValue}");
    }
}

The event is an EventCallback and it can be synchronous (return void), or it can also be asynchronous and return async Task.

The lambda expression in the handler is required by the framework: https://github.com/aspnet/AspNetCore/issues/12226.

See Also

In this article
Not finding the help you need? Improve this article