Home > Mobile >  How can I perform a function related to a razor page input field's onchange event in Blazor Ser
How can I perform a function related to a razor page input field's onchange event in Blazor Ser

Time:09-06

Hello I have an text input field in my Blazor razor page where the user has to give an Input string. I have to evaluate this input string during the user is typing the value. I have defined a function in the "onchange" event of the input object. But I don't know how I can use the input value in this function without using @bind. The main problem for me is that I cannot use @bind an @onchange at the same time. Normally I would bind the input value to variable.

<input type="text"  @onchange="Eval_input" >
@code {
private void Eval_input()
{
 // my function for evaluating the input strng    
 // here in my function I want to use the entered input string 
}
}

CodePudding user response:

You can try to use ChangeEventArgsin Eval_input.(string)e.Value is the value of input.Here is a demo:

<p>data: @data</p>
<input type="text" @onchange="Eval_input">
@code {
    private string data { get; set; }
  
    private void Eval_input(ChangeEventArgs e)
    {
        data = (string)e.Value;
        // my function for evaluating the input strng
        // here in my function I want to use the entered input string
    }
}

result:

enter image description here

  • Related