当 Textbox 通过 AJAX Toolkit AutoComplete 扩展时,面板 DefaultButton 不起作用

发布于 2024-10-30 19:30:33 字数 2417 浏览 0 评论 0原文

我正在使用 ASP.NET 面板为某些控件(如 TextBox)设置默认按钮,但由于 AJAX 控件工具包的 AutoCompleteExtender,它似乎不起作用。 请帮忙..!

代码如下:

<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>

I am using ASP.NET Panel to set Default Button for some Controls like TextBox but it seems to not work due to AJAX Control Toolkit's AutoCompleteExtender.
Pls help.. !

Code is as below:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

药祭#氼 2024-11-06 19:30:33

这样做:

 <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();
   }
}

do like this:

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

add this in script tag in your page head tag :

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

Edited to use jQuery
there is no much difference between code above and jquery :

function KeyDownHandler()
{
   if (event.keyCode == 13)
   {
      event.returnValue=false;
      event.cancel = true;
      $('#<%=lnkSearch.ClientID%>').click();
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文