1

ASP.NET Panelを使用してTextBoxなどの一部のコントロールのデフォルトボタンを設定していますが、AJAXControlToolkitのAutoCompleteExtenderが原因で機能しないようです。plsヘルプ..!

コードは次のとおりです。

<asp:Panel ID="pnlSearchBox" runat="server" class="search-main-box" DefaultButton="lnkSearch">
        <asp:TextBox ID="txtLocation" runat="server" CssClass="input-field" MaxLength="200" style="width: 182px; margin-bottom: 7px;"></asp:TextBox>
        <ajaxToolkit:AutoCompleteExtender runat="server" BehaviorID="AutoCompleteEx" ID="aceLocation" TargetControlID="txtLocation" ServicePath="~/autocomplete.asmx" ServiceMethod="GetCompletionList" MinimumPrefixLength="1" CompletionInterval="1000" EnableCaching="true" CompletionSetCount="20" CompletionListCssClass="autocomplete_completionListElement" CompletionListItemCssClass="autocomplete_listItem" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" DelimiterCharacters=";, :" ShowOnlyCurrentWordInCompletionListItem="true" >
            <Animations>
                <OnShow>
                    <Sequence>
                        <%-- Make the completion list transparent and then show it --%>
                        <OpacityAction Opacity="0" />
                        <HideAction Visible="true" />
                        <%-- Expand from 0px to the appropriate size while fading in --%>
                        <Parallel Duration=".4">
                            <FadeIn />
                            <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" />
                        </Parallel>
                    </Sequence>
                </OnShow>
                <OnHide>
                    <%-- Collapse down to 0px and fade out --%>
                    <Parallel Duration=".4">
                        <FadeOut />
                        <Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
                    </Parallel>
                </OnHide>
            </Animations>
        </ajaxToolkit:AutoCompleteExtender>
        <div class="btn-search"><asp:LinkButton ID="lnkSearch" runat="server" class="btn-search-bg" OnClick="lnkSearch_Click"><span>Search</span></asp:LinkButton>
        </div>
</asp:Panel>
4

1 に答える 1

0

このようにしてください:

 <asp:TextBox onkeydown="KeyDownHandler();" ID="txtLocation" runat="server" 
     CssClass="input-field" MaxLength="200" style="width: 182px; margin-bottom: 7px;">
 </asp:TextBox>

これをページヘッドタグのスクリプトタグに追加します。

function KeyDownHandler()
{
   if (event.keyCode == 13)
   {
      event.returnValue=false;
      event.cancel = true;
      document.getElementById('<%=lnkSearch.ClientID%>').click();
   }
}

jQueryを使用するように編集する と、上記のコードとjqueryの間に大きな違いはありません。

function KeyDownHandler()
{
   if (event.keyCode == 13)
   {
      event.returnValue=false;
      event.cancel = true;
      $('#<%=lnkSearch.ClientID%>').click();
   }
}
于 2011-04-06T05:53:58.257 に答える