Events
This article explains the events available in the Telerik Textbox for Blazor:
OnBlur
The OnBlur event fires when the component loses focus.
Handle the TextBox OnBlur event
<TelerikTextBox @bind-Value="@TextBoxValue"
OnBlur="@OnTextBoxBlur" />
<p>TextBoxValue: @TextBoxValue</p>
<p>OnBlur log: @OnBlurLog</p>
@code {
private string OnBlurLog { get; set; } = string.Empty;
private string TextBoxValue { get; set; } = "lorem ipsum";
private void OnTextBoxBlur()
{
OnBlurLog = $"OnBlur fired at {DateTime.Now.ToString("HH:mm:ss.fff")}.";
}
}
OnChange
The OnChange event represents a user action that confirms the current value. It fires when the user presses Enter or Tab in the input, or when the input loses focus. If you need to monitor the component Value while the user is typing, then use the ValueChanged event instead.
The
OnChangeevent is a custom event and does not interfere with bindings, so you can use it together with models and forms.
Handle the TextBox OnChange event and use two-way Value binding
<TelerikTextBox @bind-Value="TextBoxValue"
OnChange="@OnTextBoxChange" />
<p>TextBoxValue: @TextBoxValue</p>
<p>OnChange log: @OnChangeLog</p>
@code {
private string OnChangeLog { get; set; } = string.Empty;
private string TextBoxValue { get; set; } = "lorem ipsum";
private void OnTextBoxChange(object currentValue)
{
OnChangeLog = $"OnChange fired at {DateTime.Now.ToString("HH:mm:ss.fff")} with current value '{currentValue}'.";
}
}
The event is an
EventCallback. It can be synchronous and returnvoid, or asynchronous and returnasync Task. Do not useasync void.
ValueChanged
The ValueChanged event fires upon every change (for example, keystroke) in the input.
Handle the TextBox ValueChanged event
<TelerikTextBox Value="@TextBoxValue"
ValueChanged="@TextBoxValueChanged" />
<p>TextBoxValue: @TextBoxValue</p>
<p>ValueChanged log: @ValueChangedLog</p>
@code {
private string TextBoxValue { get; set; } = "lorem ipsum";
private string ValueChangedLog { get; set; } = string.Empty;
private void TextBoxValueChanged(string newValue)
{
TextBoxValue = newValue;
ValueChangedLog = $"ValueChanged fired at {DateTime.Now.ToString("HH:mm:ss.fff")} with a new value '{newValue}'.";
}
}
The event is an
EventCallback. It can be synchronous and returnvoid, or asynchronous and returnasync Task. Do not useasync void.