Back to Devexpress

DxSearchBox.TextChanging Event

blazor-devexpress-dot-blazor-dot-dxsearchbox-cb6e653e.md

latest2.1 KB
Original Source

DxSearchBox.TextChanging Event

Fires when a user is changing text in the editor. Use this event to validate/cancel user input.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
[Parameter]
public Action<ParameterValueChangingEventArgs<string>> TextChanging { get; set; }

Event Data

The TextChanging event's data class is ParameterValueChangingEventArgs<String>. The following properties provide information specific to this event:

PropertyDescription
NewValueGets or sets the new value being assigned to the parameter.
OldValueGets the current parameter value.

Remarks

The TextChanging event fires before a new search text is applied to the editor (before the TextChanged event). You can use this event to validate/cancel user input.

In the following code, the TextChanging event handler cancels input if the text contains specific characters (anything that is not a letter, digit, or whitespace). The current text is updated via two-way binding (@bind-Text).

razor
<DxSearchBox @bind-Text="@SearchText"
             TextChanging="@OnTextChanging">
</DxSearchBox>

<div class="mt-2">
    <span>Search text: @SearchText</span>
</div>

@code {
    string SearchText { get; set; }

    private void OnTextChanging(ParameterValueChangingEventArgs<string> e) {
        if (e.NewValue.Any(c => !char.IsLetterOrDigit(c) && !char.IsWhiteSpace(c))) {
            e.NewValue = e.OldValue;
        }
    }
}

See Also

DxSearchBox Class

DxSearchBox Members

DevExpress.Blazor Namespace