I have the following code.
<input id="search" type="text" @bind="Search" @onkeypress="SearchChanged" />
@code {
string Search;
void SearchChanged()
{
var s = Search; // Search is always one character behind
}
}
Typing in the text box will trigger the function SearchChanged
. However, the value it got is always one character before the typed text. For example, setting a break point in SearchChanged
,
Typed Value of Search ===== ================ a null ab a abc ab abcd abc
BTW, the @onkeypress
doesn't work in Internet Browser?
Tried to change the code to
<input id="search" type="text" @bind="Search" />
@code {
string search;
string Search
{
get { return search; }
set {
search = value;
ResultList = GetNewList(search).Result.ToList();
}
}
void SearchChanged()
{
var s = Search; // Search is always one character behind
}
}
I set a break point in the set { }
, however, the break point is hit just one or two times when typing the text box?