【问题标题】:AutoComplete Extender in Master Page母版页中的自动完成扩展器
【发布时间】:2010-12-08 22:08:42
【问题描述】:

我浏览了很多论坛、帖子等。但从未找到真正好的答案。 我正在尝试将 AutoComplete Extender 添加到 TextBox 并向用户显示一些提示。 将此代码放在内容页面中时一切正常。但是我有大约 10 个基于一个母版页的内容页面,所以在每个页面上重复代码是完全愚蠢的。

网上有一些答案,但只是部分答案,请检查您是否愿意:

Could post only one link :/

这是我的代码:

母版页:

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="~/AutoComplete.asmx" />
    </Services>
</asp:ScriptManager>

<asp:TextBox runat="server" ID="TextBox1"></asp:TextBox>
            <ajax:AutoCompleteExtender 
                ID="AutoCompleteExtender1" 
                runat="server" 
                TargetControlID="TextBox1"
                ServiceMethod="GetCompletionList"
                ServicePath="~/AutoComplete.asmx"
                MinimumPrefixLength="1"
                CompletionInterval="500"
                CompletionSetCount="2">
            </ajax:AutoCompleteExtender>

网络服务:

/// <summary>
/// Summary description for AutoComplete
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService
{        
    [WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public string[] GetCompletionList(string prefixText, int count)
    {
        // Create array of movies  
        string[] movies = { "Star Wars", "Star Trek", "Superman", "Memento", "Shrek", "Shrek II" };

        // Return matching movies  
        return (from m in movies where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
    }
}

作为记录,我检查了 Web 服务,它工作得很好

附言这是我的第一篇文章,如果我做错了什么,请见谅

【问题讨论】:

    标签: asp.net asp.net-ajax


    【解决方案1】:

    面临类似的问题,但似乎唯一的解决方案是在内容页面本身中编写 Web 方法,并且可以将带有各自控件的自动完成扩展器保留在母版页中。

    【讨论】:

      猜你喜欢
      • 2012-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-02
      • 2011-11-15
      相关资源
      最近更新 更多