本文介绍了检测AutoCompleteExtender select事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是捕捉AutoCompleteExtender select事件最好的方法,因为控件没有这个活动?

下面是样品,我说什么。我有两个texboxes(Location1TextBox,Location2TextBox)与联AutoCompleteExtender控制。这部分工作得很好。现在,当用户进行选择构成任何AutoCompleteExtender我需要赶上这一事件,并尝试LOCATION1和LOCATION2之间计算距离的问题。结果应该是全自动填充到DistanceTextBox。任何好的sugesstions?我只希望它不会与onchange事件的文本框...

结束

 < ASP:的UpdatePanel ID =UpdatePanel2=服务器>
        <&的ContentTemplate GT;
            < ASP:标签ID =TitleLabel=服务器文本='<%$资源:鸭$ P $的PSource,LocationStart%GT;'
                的CssClass =OneColumnLabel>< / ASP:标签>:< BR />
            < ASP:文本框ID =Location1TextBox=服务器的CssClass =TwoColumnMiddleLongText
                的ValidationGroup =编辑的AutoPostBack =真>< / ASP:文本框> *
            < ASP:的RequiredFieldValidator ID =TitleRequiredFieldValidator=服务器的ControlToValidate =Location1TextBox
                显示=无的ErrorMessage ='<%$资源:鸭$ P $的PSource,LocationRequired%GT;'的ValidationGroup =编辑>< / ASP:&的RequiredFieldValidator GT;
            < ajaxToolkit:AutoCompleteExtender =服务器ID =AutoCompleteExtender1的TargetControlID =Location1TextBox
                ServiceMethod =GetCompletionListServicePath =TravelOrder.aspx最低prefixLength =1
                CompletionInterval =300UseContextKey =真>
            < / ajaxToolkit:AutoCompleteExtender>
            < ASP:标签ID =Label7=服务器文本='<%$资源:鸭$ P $的PSource,LocationArrival%GT;'
                的CssClass =OneColumnLabel>< / ASP:标签>:< BR />
            < ASP:文本框ID =Location2TextBox=服务器的CssClass =TwoColumnMiddleLongText
                的ValidationGroup =编辑>< / ASP:文本框> *
            < ASP:的RequiredFieldValidator ID =RequiredFieldValidator3=服务器的ControlToValidate =Location2TextBox
                显示=无的ErrorMessage ='<%$资源:鸭$ P $的PSource,LocationRequired%GT;'的ValidationGroup =编辑>< / ASP:&的RequiredFieldValidator GT;
            < ajaxToolkit:AutoCompleteExtender =服务器ID =AutoCompleteExtender2的TargetControlID =Location2TextBox
                ServiceMethod =GetCompletionListServicePath =TravelOrder.aspx最低prefixLength =1
                CompletionInterval =300UseContextKey =真>
            < / ajaxToolkit:AutoCompleteExtender>
            < ASP:标签ID =的Label8=服务器文本='<%$资源:鸭$ P $的PSource,距离%GT;'
                的CssClass =OneColumnLabel>< / ASP:标签>:< BR />
            < ASP:文本框ID =DistanceTextBox=服务器的CssClass =OneColumnText的ValidationGroup =编辑>< / ASP:文本框> *
            < ASP:的RequiredFieldValidator ID =RequiredFieldValidator4=服务器的ControlToValidate =DistanceTextBox
                显示=无的ErrorMessage ='<%$资源:鸭$ P $的PSource,DistanceRequired%GT;'的ValidationGroup =编辑>< / ASP:&的RequiredFieldValidator GT;
        < /&的ContentTemplate GT;
    < / ASP:的UpdatePanel>


解决方案

您可以删除的AutoPostBack =真正的从目标文本框,订阅的TextChanged事件和使用功能以下为处理程序itemSelected扩展的客户端事件 OnClientItemSelected =autoCompleteEx_ItemSelected

 <脚本类型=文/ JavaScript的>
     功能autoCompleteEx_ItemSelected(发件人,参数){
          __doPostBack(sender.get_element()的名字,);
     }
< / SCRIPT>

What is the best approach to capture AutoCompleteExtender select event, since control does not have this event?

Here is sample I am talking about. I have two texboxes (Location1TextBox,Location2TextBox) with linked AutoCompleteExtender controls. This part works well. Now the problem is when user makes selection form any AutoCompleteExtender I need to catch this event and try to calculate distance between location1 and location2. Result should be populated to DistanceTextBox automaticly. Any good sugesstions? I just hope it would not end up with onchange event for textboxes...

    <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>
解决方案

You may remove AutoPostBack="true" from a target textbox, subscribe on TextChanged event and use function below as handler for itemSelected extender's client event OnClientItemSelected="autoCompleteEx_ItemSelected":

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

这篇关于检测AutoCompleteExtender select事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 07:52