这是c#.net 2.0。我正在使用母版页。
文件:
EditTicket.aspx AutoComplete.asmx App_Code文件/ AutoComplete.cs
EditTicket.aspx:
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc2" %>
<asp:ScriptManager id="ScriptManager1" runat="server" EnablepageMethods="true">
<Services>
<asp:ServiceReference Path="AutoComplete.asmx" />
</Services>
</asp:ScriptManager>
<cc2:AutoCompleteExtender
runat="server"
ID="AutoCompleteExtender1"
ServicePath="AutoComplete.asmx"
ServiceMethod="AutoComplete2"
MinimumPrefixLength="1"
CompletionSetCount="12"
TargetControlID="TextBox3"
EnableCaching="True" >
</cc2:AutoCompleteExtender>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
AutoComplete.asmx:
<%@ WebService Language="C#" CodeBehind="~/App_Code/AutoComplete.cs" Class="AutoComplete" %>
AutoComplete.cs:
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
/// <summary>
/// Summary description for AutoComplete
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class AutoComplete : System.Web.Services.WebService {
public AutoComplete () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
[ScriptMethod]
public string[] AutoComplete2(string prefixText,int count)
{
string conString = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
SqlConnection connection = new SqlConnection(conString);
connection.Open();
SqlParameter prm;
string sql = "Select program_name FROM CM_Programs WHERE program_name LIKE @prefixText";
SqlDataAdapter cmd = new SqlDataAdapter(sql, connection);
prm = new SqlParameter("@prefixText", SqlDbType.VarChar, 50);
prm.Value = prefixText+ "%";
cmd.SelectCommand.Parameters.Add(prm);
DataTable dt = new DataTable();
cmd.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["program_name"].ToString(),i);
i++;
}
connection.Close();
return items;
}
}
答案 0 :(得分:1)
“没有任何事情发生”并不是一个简单的描述。当你说什么都没发生时,你检查过那个
如果“没有”是上述情况都没有发生,我会开始检查页面上是否存在javascript错误,并且您的AutoComplete扩展程序是否正确呈现(检查跟踪中的页面控件)。
答案 1 :(得分:1)
尝试摆弄CompletionInterval属性。我在过去使用过这个控件,直到我将CompletionInterval设置为更低的值才看到我预期的行为。它默认为1000(ms),我会给它一个值为1的镜头,只是为了看一切是否正常工作(并且womp的步骤应该有助于缩小通信问题发生的位置),如果它确实如此工作,继续增加值,直到你达到一个有意义的值(1毫秒向服务器发送大量的请求)。报告哪些有效,哪些无效。