我需要一个用于 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>
更新:我尝试使用该建议,但出现此错误:
$find("PlantDropDown") 为 null
[打破此错误]
$find('PlantDropDown').add_propertyChanged(function(sender, e) {\r\n
我在 Javascript 端使用 jQuery,顺便说一句,以防万一。
最后更新:
感谢 crescentfresh 的帮助,我让它工作了,最后我的 .aspx 文件中有这个:
<input type="hidden" id="PlantDropDownID" value="<%= PlantDropDown.ClientID %>" />
这是在我的 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;
}
})