0
我正在使用Asp.net 4.5,我在不使用Web服务的情况下实现了自动填充扩展器,但它不起作用。这里是我的代码ASP.Net AJAX控件工具包AutoCompleteExtender不使用Web服务
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ServiceMethod="SearchCustomers"
MinimumPrefixLength="21"
CompletionInterval="100" EnableCaching="true" CompletionSetCount="100"
TargetControlID="TextBox1"
ID="AutoCompleteExtender1" runat="server" FirstRowSelected = "false">
这里是我的aspx代码: -
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> SearchCustomers(string prefixText, int count)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = "server=.; database=northwind; integrated security=true";
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select name from patientHistory where name like @SearchText +'%'";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = conn;
conn.Open();
List<string> customers = new List<string>();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(sdr["name"].ToString());
}
}
conn.Close();
return customers;
}
}
}
你说这不工作,但你不知道提供更多细节。您是否在服务器端或客户端获取错误消息?你的服务器端功能是否被调用?您是否使用过浏览器的调试工具和/或Fiddler查看请求和响应? – mason
我使用断点的代码工作正常,但自动完成不工作的.aspx页面 – user3364191
Your MinimumPrefixLength是21.这非常高。在激活自动完成之前,您必须键入21个字符。如果您使用浏览器工具或Fiddler查看请求和响应,您仍然没有提及。 – mason