简体   繁体   English

ASP.NET中的Ajax自动完成文本框在母版页中不起作用

[英]Ajax Auto-complete Text Box in ASP.NET does not work within master page

This example works fine with a normal asp.net page. 此示例在正常的asp.net页面上正常工作。 but using with a master page , it does not work. 但是与母版页一起使用则无法正常工作。

The masterpage.master masterpage.master

 <asp:TextBox ID="TextBoxSearchCompany" class="form-control" placeholder="Search company..." runat="server"/>
                         <asp:AutoCompleteExtender ID="txtName_AutoCompleteExtender" runat="server" DelimiterCharacters="" Enabled="True" ServiceMethod="GetCompletionList" 
                            ServicePath="" TargetControlID="TextBoxSearchCompany" UseContextKey="True" MinimumPrefixLength="2" CompletionInterval="10" EnableCaching="true" CompletionSetCount="3">
                        </asp:AutoCompleteExtender>

The masterpage code behind 母版页背后的代码

        [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
    {
        string connectionString = ConnectionString.GetConStr();
        SqlConnection conn = new SqlConnection(connectionString);
        // Try to use parameterized inline query/sp to protect sql injection
        SqlCommand cmd = new SqlCommand("SELECT TOP " + count + " company FROM [vwCompanyLookup] WHERE company LIKE '" + prefixText + "%'", conn);
        SqlDataReader oReader;
        conn.Open();
        List<string> CompletionSet = new List<string>();
        oReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        while (oReader.Read())
            CompletionSet.Add(oReader["company"].ToString());
        return CompletionSet.ToArray();
    }

any help to solve to this problem. 解决此问题的任何帮助。

在servicepath中输入服务名称-> GetCompletionList

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM