This is a migrated thread and some comments may be shown as answers.

Load on Demand OnChange event firing twice

1 Answer 345 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Admin
Top achievements
Rank 1
Admin asked on 12 Feb 2011, 11:56 PM

Hi,

Currently I'm using this code to load a dropdownlist when the user clicks the down arrow.  (On Demand)

@(Html.Telerik().DropDownList().Name(
"AjaxDropDownList").DataBinding(binding => binding.Ajax().Select("_AjaxLoading","Home")).ClientEvents(events => events.OnChange("Editor_onChange")) )

The dropdown populates correctly however the OnChange Event seems to be firing 2 times.   The first value gets selected and calls Onchange before you have a chance to pick the correct value in the dropdown.

function Editor_onChange(e) {alert("OnChange called");}

Telerk Version: 2010.3.1318.340
ASP.NET 4.0 C# MVC3 Razor
Internet Explorer 8, Windows 7

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 14 Feb 2011, 02:15 PM
Hello Mike,

 The aforementioned behavior is expected. Change event will be raised on user click when SelectedIndex is set and the component is bind with Ajax. 

You can overcome this issue with the following code snippet:

function ddlDataBound(e) {
    var ddl = $(this).data("tDropDownList");
    var item = ddl.data[ddl.index];
    ddl.previousValue = item.Value || item.Text;
}
As you note, you will need to wire onDataBound client event and set internal previousValue variable to the correct value.

Best regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
Admin
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or