打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

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

我需要一个用于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") is null[Break on this error] $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;    }})

解决方法:

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

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

与通常的警告约.NET control ids in the client.

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

编辑:

&GT $find(“PlantDropDown”)为空

确保使用正确的ID.请参阅.NET control ids in the client.要获得参考,您可能需要执行以下操作:

$find('<%= PlantDropDown.ClientID %>')

&GT我在javascript方面使用jQuery

这没有任何意义.

来源:https://www.icode9.com/content-1-349851.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
使用AutoCompleteExtender实现文本框自动匹配
将 Ajax 带入 Eclipse 的 Ajax Toolkit Framework 的两个工具
使用 Ajax Toolkit Framework 开发 Dojo 应用
Google Web Toolkit-用Java编写AJAX
Ajax JavaScript resources at Savage Vines
本周ASP.NET英文技术文章推荐[07/29 - 08/04]
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服