捕获AutoCompleteExtender select事件的最佳方法是什么,因为控件没有此事件?
这是我正在谈论的样本。我有两个带有链接AutoCompleteExtender控件的texbox(Location1TextBox,Location2TextBox)。这部分效果很好。现在问题是当用户从任何AutoCompleteExtender中选择时我需要捕获此事件并尝试计算location1和location2之间的距离。结果应自动填充到DistanceTextBox。有什么好的sugesstions?我只是希望它不会以文本框的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>
答案 0 :(得分:6)
您可以从目标文本框中删除AutoPostBack="true"
,订阅TextChanged事件并使用下面的函数作为itemSelected extender的客户端事件OnClientItemSelected="autoCompleteEx_ItemSelected"
的处理程序:
<script type="text/javascript">
function autoCompleteEx_ItemSelected(sender, args) {
__doPostBack(sender.get_element().name, "");
}
</script>