TelerikComboBox firing OnChange twice

2 Answers 1277 Views
ComboBox
Martin Herløv
Top achievements
Rank 2
Bronze
Iron
Iron
Martin Herløv asked on 27 Aug 2021, 02:38 PM

Hi when I select an item I get a change event as expected, but I also got one on lostfocus, when I tab away.

 


  <td class="pe-3"><TelerikComboBox
            Data="@ComboItems"
            TextField="Name"
             ValueField="Id"
             @bind-Value="SelectedValue"
             OnChange="ValueChangedHandler"/></td>

private void ValueChangedHandler(object value)
        {
            int id = (int) value;
            Console.WriteLine("" + id);
        }
ValueChangedHandler called twice


2 Answers, 1 is accepted

Sort by
0
Matthias
Top achievements
Rank 5
Bronze
Bronze
Iron
answered on 27 Aug 2021, 04:36 PM
I'm pretty sure that the binding only occurs when you leave the ComoBox. Without binding, "ValueChanged" would be called only once. Try this without binding and use only "Value". This will be the case for all input fields.
0
Marin Bratanov
Telerik team
answered on 28 Aug 2021, 09:57 AM

Hi Martin,

Take a look at this article which describes this behavior and two ways to avoid it: https://docs.telerik.com/blazor-ui/knowledge-base/common-onchange-fires-twice

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ComboBox
Asked by
Martin Herløv
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Matthias
Top achievements
Rank 5
Bronze
Bronze
Iron
Marin Bratanov
Telerik team
Share this question
or