5

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

这是我正在谈论的示例。我有两个带有链接 AutoCompleteExtender 控件的 texboxes(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>
4

1 回答 1

6

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

<script type="text/javascript">
     function autoCompleteEx_ItemSelected(sender, args) {
          __doPostBack(sender.get_element().name, "");
     }
</script>
于 2012-10-12T08:40:29.483 回答