Live Chat Icon For mobile
Live Chat Icon

How to read the current value of an input in the OnKeyPress event?

Platform: Blazor| Category: Event handling

To read the current value of an input using @onkeypress event, this event uses the KeyboardEventArgs. You can also get the last pressed key value in args.Key.

[index.razor]

@page"/"

<input type="text" @onkeypress="@Keypress" />
<h1>@KeyPressed</h1>

@code {
    string KeyPressed = "";
    private void Keypress(KeyboardEventArgs args)
    {
        KeyPressed = "Key Pressed is " + args.Key;
    }
}

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.