与 AutoCompleteExtender 一起使用时 OnTextChanged 不起作用
OnTextChanged not working when used with AutoCompleteExtender
我有一个如下所示的文本框:
Search:<asp:TextBox runat="server" ID="txtSearchCompany" AutoPostBack="true" OnTextChanged="txtSearchCompany_TextChanged"></asp:TextBox>
我还有一个 AutoCompleteExtender
链接到文本框,如下所示:
<cc1:AutoCompleteExtender ServiceMethod="SearchCustomers"
MinimumPrefixLength="2"
CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtSearchCompany"
ID="AutoCompleteExtender1" runat="server"
CompletionListElementID="autocompleteDropDownPanel"
>
</cc1:AutoCompleteExtender>
当我从 AutoComplete
列表中选择某项时,它不会触发 onTextChanged
事件。但是,如果我在文本框中键入内容并且我没有 select AutoComplete
列表中的值,它会触发 onTextChanged
.
谁能告诉我这是怎么回事?
谢谢
据我所知,自动完成逻辑和文本框控件不会像您期望的那样协同工作,因为 OnTextChanged 事件仅在文本框中也有 typed/changed 时才会触发。尽管从自动完成下拉列表中选择了不同的值,但此事件不会起作用。
有这个link,不准确,但也指向同一个方向。
Check this.
可能有一些解决方法,当从下拉列表中选择一个值时,您可以通过这些方法触发事件。
您可以尝试在 JavaScript/jQuery 中编写一个 ajax 事件,这会在服务器上为此触发一个事件,然后您可以在服务器上执行逻辑并 return 数据作为通过脚本的响应。
以此为例:
这是示例代码:
function autocomplete() {
$('.control').autocomplete({
source: function (request, response) {
// ajax code to perform textChange logic
},
minLength: 1,
change: function (event, ui) { SaveData(); }
});
}
希望对您有所帮助。
使用客户端脚本中的 OnClientItemSelected 事件来触发 TextChanged 事件
<cc1:AutoCompleteExtender ServiceMethod="SearchCustomers"
MinimumPrefixLength="2"
CompletionInterval="100"
EnableCaching="false"
CompletionSetCount="10"
TargetControlID="txtSearchCompany"
ID="AutoCompleteExtender1" runat="server"
CompletionListElementID="autocompleteDropDownPanel"
OnClientItemSelected="DoTextChangedPostBack" >
</cc1:AutoCompleteExtender>
<script type="text/javascript" language="javascript">
function DoTextChangedPostBack(source, eventArgs) {
var hfield = $get('<%=txtSearchCompany.ClientID%>');
hfield.value = eventArgs.get_value();
__doPostBack("<%=txtSearchCompany.ID%>", "TextChanged");
}
</script>
我有一个如下所示的文本框:
Search:<asp:TextBox runat="server" ID="txtSearchCompany" AutoPostBack="true" OnTextChanged="txtSearchCompany_TextChanged"></asp:TextBox>
我还有一个 AutoCompleteExtender
链接到文本框,如下所示:
<cc1:AutoCompleteExtender ServiceMethod="SearchCustomers"
MinimumPrefixLength="2"
CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtSearchCompany"
ID="AutoCompleteExtender1" runat="server"
CompletionListElementID="autocompleteDropDownPanel"
>
</cc1:AutoCompleteExtender>
当我从 AutoComplete
列表中选择某项时,它不会触发 onTextChanged
事件。但是,如果我在文本框中键入内容并且我没有 select AutoComplete
列表中的值,它会触发 onTextChanged
.
谁能告诉我这是怎么回事?
谢谢
据我所知,自动完成逻辑和文本框控件不会像您期望的那样协同工作,因为 OnTextChanged 事件仅在文本框中也有 typed/changed 时才会触发。尽管从自动完成下拉列表中选择了不同的值,但此事件不会起作用。
有这个link,不准确,但也指向同一个方向。 Check this.
可能有一些解决方法,当从下拉列表中选择一个值时,您可以通过这些方法触发事件。
您可以尝试在 JavaScript/jQuery 中编写一个 ajax 事件,这会在服务器上为此触发一个事件,然后您可以在服务器上执行逻辑并 return 数据作为通过脚本的响应。
以此为例:
这是示例代码:
function autocomplete() {
$('.control').autocomplete({
source: function (request, response) {
// ajax code to perform textChange logic
},
minLength: 1,
change: function (event, ui) { SaveData(); }
});
}
希望对您有所帮助。
使用客户端脚本中的 OnClientItemSelected 事件来触发 TextChanged 事件
<cc1:AutoCompleteExtender ServiceMethod="SearchCustomers"
MinimumPrefixLength="2"
CompletionInterval="100"
EnableCaching="false"
CompletionSetCount="10"
TargetControlID="txtSearchCompany"
ID="AutoCompleteExtender1" runat="server"
CompletionListElementID="autocompleteDropDownPanel"
OnClientItemSelected="DoTextChangedPostBack" >
</cc1:AutoCompleteExtender>
<script type="text/javascript" language="javascript">
function DoTextChangedPostBack(source, eventArgs) {
var hfield = $get('<%=txtSearchCompany.ClientID%>');
hfield.value = eventArgs.get_value();
__doPostBack("<%=txtSearchCompany.ID%>", "TextChanged");
}
</script>