【问题标题】:AutocompleteExtender not working in master pageAutocompleteExtender 在母版页中不起作用
【发布时间】:2011-03-11 10:31:52
【问题描述】:

我对 ASP.NET 中的自动完成扩展程序有疑问 - 它在我拥有的所有页面中都可以正常工作,但在母版页中却没有,我不知道为什么。

这是我的代码:

<asp:TextBox runat="server" ID="txtSearch" Width="200px" CssClass="TextBoxClass"></asp:TextBox>
<cc1:AutoCompleteExtender ID="txtSearch_AutoCompleteExtender" runat="server" 
    TargetControlID="txtSearch"
    CompletionInterval="0" 
    CompletionListCssClass="autocomplete_completionListElement"
    CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" 
    CompletionListItemCssClass="autocomplete_listItem"
    CompletionSetCount="10" EnableCaching="true" MinimumPrefixLength="2" 
    ServiceMethod="GetCompletionListOggetti"
    ShowOnlyCurrentWordInCompletionListItem="true" UseContextKey="True">
</cc1:AutoCompleteExtender>

后面的代码:

<System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()> _
Public Shared Function GetCompletionListOggetti(ByVal prefixText As String, ByVal count As Integer) As String()
    ' Insert code to return a string array here…
    Return AutoCompleteOggetti(prefixText)
End Function

问题是GetCompletionListOggetti 永远不会被调用。

我再说一遍 - 它在内容页面上运行良好!提前致谢。

【问题讨论】:

    标签: asp.net vb.net autocomplete


    【解决方案1】:

    您需要设置 AutoCompleteExtender 的 ServicePath 属性来覆盖回调加载(非主)页面的默认行为。

    将您的函数添加到 Web 服务页面 (.asmx)、虚拟页面或 default.aspx 等的代码隐藏中。

    如果使用网络服务页面,您需要添加/取消注释该行:

    <System.Web.Script.Services.ScriptService()> _
    

    对于 VB,或者对于 C#

    [System.Web.Script.Services.ScriptService]
    

    【讨论】:

      【解决方案2】:

      我通过将 Web 方法(在您的情况下为 GetCompletionListOggetti)放在内容页面而不是母版页的代码隐藏文件中来管理它。它仅适用于同一代码隐藏文件中的 Web 方法,而不适用于单独的 asmx 服务中。为此,不要忘记将 EnablePageMethods="true" 属性也添加到您的脚本管理器中。

      当 AutoCompleteExtender 的服务方法在用户(或自定义)控件的代码隐藏文件中定义时,似乎永远不会调用它,并且母版页确实是一种控件。

      此修复的缺点是您必须在使用此母版页的每个内容页面中放置相同的服务方法。不是很优雅。另一个缺点是建议下拉列表的 css 无法正常工作。我仍然无法弄清楚周围的情况。有更好的主意吗?

      【讨论】:

      • “此修复的缺点是您必须在使用此母版页的每个内容页面中放置相同的服务方法。”继承?
      猜你喜欢
      • 2014-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-29
      • 2012-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多