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

Events

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

OnChange

The OnChange event represents a user action - confirmation of the current value. It fires when the user presses Enter in the input, or when the input loses focus.

Handle OnChange

@result
<br />

<TelerikTextBox OnChange="@MyOnChangeHandler"></TelerikTextBox>

@code {
    string result;

    private void MyOnChangeHandler(object theUserInput)
    {
        // the handler receives an object that you may need to cast
        result = string.Format("The user entered: {0}", theUserInput);
    }
}

The event is an EventCallback. It can be synchronous and return void, or asynchronous and return async Task. Do not use async void.

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

Handle OnChange and use two-way binding

@result
<br />
model value: @theTbValue
<br />

<TelerikTextBox OnChange="@MyOnChangeHandler" @bind-Value="theTbValue"></TelerikTextBox>

@code {
    string result;

    string theTbValue { get; set; } = "lorem ipsum";

    private void MyOnChangeHandler(object theUserInput)
    {
        // the handler receives an object that you may need to cast
        result = string.Format("The user entered: {0}", theUserInput);
    }
}

ValueChanged

The ValueChanged event fires upon every change (for example, keystroke) in the input.

Handle ValueChanged

@result
<br />

<TelerikTextBox ValueChanged="@MyValueChangeHandler"></TelerikTextBox>

@code {
    string result;

    private void MyValueChangeHandler(string theUserInput)
    {
        result = string.Format("The user entered: {0}", theUserInput);
    }
}

The event is an EventCallback. It can be synchronous and return void, or asynchronous and return async Task. Do not use async void.

Handle ValueChanged and provide initial value

from the handler: @result
<br />
from model: @theTbValue
<br />

<TelerikTextBox ValueChanged="@MyValueChangeHandler" Value="@theTbValue"></TelerikTextBox>

@code {
    string result;

    public string theTbValue { get; set; } = "lorem ipsum";

    private void MyValueChangeHandler(string theUserInput)
    {
        result = string.Format("The user entered: {0}", theUserInput);

        //you have to update the model manually because handling the ValueChanged event does not let you use @bind-Value
        theTbValue = theUserInput;
    }
}

OnBlur

The OnBlur event fires when the component loses focus.

Handle the OnBlur event

@* You do not have to use OnChange to react to loss of focus *@

<TelerikTextBox @bind-Value="@TheValue"
                OnBlur="@OnBlurHandler">
</TelerikTextBox>

@code{
    async Task OnBlurHandler()
    {
        Console.WriteLine($"BLUR fired, current value is {TheValue}.");
    }

    string TheValue { get; set; }
}

See Also

In this article