当文本框更改时,如何将javascript事件处理程序绑定到Ajax Control Toolkit组合框

Jam*_*ack 3 javascript jquery combobox ajaxcontroltoolkit javascript-events

我需要一个用于ASP.NET项目的组合框,所以我决定使用Ajax Control Toolkit组合框(http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ComboBox/ComboBox.aspx).

我不想使用回发,因为我不想重新加载页面,但我需要知道文本框中的文本何时更改,以便我可以调用服务器来保留新的列表项.

我很好奇如何将onchange或onblur事件绑定到此组合框使用的输入框.

这是我的asp.net页面:

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<cc1:ComboBox ID="PlantDropDown" runat="server" OnInit="PlantDropDown_Init" DropDownStyle="DropDown" 
             AutoCompleteMode="SuggestAppend" 
            ItemInsertLocation="OrdinalText" AutoPostBack="false">


                </cc1:ComboBox>
Run Code Online (Sandbox Code Playgroud)

更新:我尝试使用该建议,我收到此错误:

$find("PlantDropDown") is null
[Break on this error] $find('PlantDropDown').add_propertyChanged(function(sender, e) {\r\n
Run Code Online (Sandbox Code Playgroud)

我在javascript方面使用jQuery,顺便说一句,如果有帮助的话.

最后更新:感谢crescentfresh的帮助,我得到了它的工作,最后我在.aspx文件中有这个:

    <input type="hidden" id="PlantDropDownID" value="<%= PlantDropDown.ClientID %>" />
Run Code Online (Sandbox Code Playgroud)

这是在我的javascript文件中,因为我不在我的.aspx文件中推送javascript:

elem = document.getElementById('PlantDropDownID');
$find(elem.value).add_propertyChanged(function(sender, e) {
    if (e.get_propertyName() == 'selectedIndex') {
        var newValue = sender.get_textBoxControl().value;
    }
})
Run Code Online (Sandbox Code Playgroud)

Cre*_*esh 8

我相信你应该绑定到"propertyChanged"事件并检查"selectedIndex"属性的更改:

$find('PlantDropDown').add_propertyChanged(function(sender, e) {
    if (e.get_propertyName() == 'selectedIndex') {
        var newValue = sender.get_textBoxControl().value;

        // persist selected value here...
    }
})
Run Code Online (Sandbox Code Playgroud)

关于客户端中.NET控件ID的常见警告.

api并不容易,这是肯定的..get_value()例如,没有方法,这将是很好的,而不必通过嵌入的文本框控件.

编辑:

> $ find("PlantDropDown")为空

确保使用正确的ID.请参阅客户端中的.NET控件ID.要获得参考,您可能需要做:

$find('<%= PlantDropDown.ClientID %>')
Run Code Online (Sandbox Code Playgroud)

>我在javascript方面使用jQuery

这没有任何意义.