AutoCompleteExtender突然停止工作

时间:2016-11-10 11:07:42

标签: c# asp.net ajaxcontroltoolkit autocompleteextender

我在我的一个项目中实现了AjaxControlToolkit AutoCompleteExtender,它运行正常。突然有一天,当我打开项目时,AutoCompleteExtender停止了工作。 Toolkit的所有其他功能(如日历控件)工作正常。

为了调查此问题,我尝试创建一个新的Web应用程序并在新应用程序中复制相同的代码,但它工作正常。可以用这种方式来帮助。

我正在使用AjaxControlToolkit的4.1.50731版本,下面是我编写的代码。

注册大会:

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

Aspx Page:

<form id="form1" runat="server">
    <div>
        <span class="span-formitem">
            <asp:Label ID="lblName" runat="server" Text="Name"></asp:Label><br />
            <cc1:ToolkitScriptManager runat="server" ID="ToolkitScriptManager1" EnablePageMethods="true"></cc1:ToolkitScriptManager>
            <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
            <cc1:AutoCompleteExtender ServiceMethod="SearchEmployees"
                MinimumPrefixLength="3"
                CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
                TargetControlID="txtName"
                ID="AutoCompleteExtender1" runat="server" FirstRowSelected="false">
            </cc1:AutoCompleteExtender>
        </span>
    </div>
</form>

获取数据的代码:

[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod()]
public static List<string> SearchEmployees(string prefixText, int count)
{
    using (SqlConnection conn = new SqlConnection())
    {
        conn.ConnectionString = "Data Source=dd-SQL21;Database=CMCM;User ID=CMCM;Password=xx@12xx";

        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "select top 15 employeename" + " from employee_master" + " where employeename like '%" + prefixText + "%'" +
                " order by (case when employeename like '" + prefixText + "%' then 1" + " when employeename like '% " + prefixText + "%' then 2" +
                    " else 3" + " end);";
            cmd.Parameters.AddWithValue("@SearchText", prefixText);
            cmd.Connection = conn;
            conn.Open();
            List<string> employees = new List<string>();
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    employees.Add(sdr["employeename"].ToString());
                }
            }
            conn.Close();
            return employees;
        }
    }
}

0 个答案:

没有答案