gpt4 book ai didi

c# - 检测 AutoCompleteExtender 选择事件

转载 作者:太空狗 更新时间:2023-10-29 23:09:11 25 4
gpt4 key购买 nike

捕获 AutoCompleteExtender 选择事件的最佳方法是什么,因为控件没有此事件?

这是我正在谈论的示例。我有两个带有链接的 AutoCompleteExtender 控件的文本框(Location1TextBox、Location2TextBox)。这部分效果很好。现在的问题是,当用户从任何 AutoCompleteExtender 中进行选择时,我需要捕获此事件并尝试计算 location1 和 location2 之间的距离。结果应自动填充到 DistanceTextBox。有什么好的建议吗?我只是希望它不会以文本框的 onchange 事件结束......

    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Label ID="TitleLabel" runat="server" Text='<% $resources:AppResource,LocationStart %>'
CssClass="OneColumnLabel"></asp:Label>:<br />
<asp:TextBox ID="Location1TextBox" runat="server" CssClass="TwoColumnMiddleLongText"
ValidationGroup="Edit" AutoPostBack="true"></asp:TextBox>*
<asp:RequiredFieldValidator ID="TitleRequiredFieldValidator" runat="server" ControlToValidate="Location1TextBox"
Display="None" ErrorMessage='<% $resources:AppResource,LocationRequired %>' ValidationGroup="Edit"></asp:RequiredFieldValidator>
<ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtender1" TargetControlID="Location1TextBox"
ServiceMethod="GetCompletionList" ServicePath="TravelOrder.aspx" MinimumPrefixLength="1"
CompletionInterval="300" UseContextKey="True">
</ajaxToolkit:AutoCompleteExtender>
<asp:Label ID="Label7" runat="server" Text='<% $resources:AppResource,LocationArrival %>'
CssClass="OneColumnLabel"></asp:Label>:<br />
<asp:TextBox ID="Location2TextBox" runat="server" CssClass="TwoColumnMiddleLongText"
ValidationGroup="Edit"></asp:TextBox>*
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="Location2TextBox"
Display="None" ErrorMessage='<% $resources:AppResource,LocationRequired %>' ValidationGroup="Edit"></asp:RequiredFieldValidator>
<ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtender2" TargetControlID="Location2TextBox"
ServiceMethod="GetCompletionList" ServicePath="TravelOrder.aspx" MinimumPrefixLength="1"
CompletionInterval="300" UseContextKey="True">
</ajaxToolkit:AutoCompleteExtender>
<asp:Label ID="Label8" runat="server" Text='<% $resources:AppResource,Distance %>'
CssClass="OneColumnLabel"></asp:Label>:<br />
<asp:TextBox ID="DistanceTextBox" runat="server" CssClass="OneColumnText" ValidationGroup="Edit"></asp:TextBox>*
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="DistanceTextBox"
Display="None" ErrorMessage='<% $resources:AppResource,DistanceRequired %>' ValidationGroup="Edit"></asp:RequiredFieldValidator>
</ContentTemplate>
</asp:UpdatePanel>

最佳答案

您可以从目标文本框中删除 AutoPostBack="true",订阅 TextChanged 事件并使用下面的函数作为 itemSelected 扩展程序客户端事件的处理程序 OnClientItemSelected="autoCompleteEx_ItemSelected" :

<script type="text/javascript">
function autoCompleteEx_ItemSelected(sender, args) {
__doPostBack(sender.get_element().name, "");
}
</script>

关于c# - 检测 AutoCompleteExtender 选择事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12838552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com