我在我的 ASP.net 页面中使用 ajax 自动完成扩展器控件作为文本框:
<td align="left>
<asp:TextBox ID="txtAutoComplete" runat="server" MaxLength="200" Width="50%"> </asp:TextBox>
<asp:AutoCompleteExtender ID="txtAutoComplete_AutocompleteExtender" runat="server"
Enabled="true" TargetControlID="txtAutoComplete" UseContextKey="true" ServiceMethod="GetItemsList" ServicePath="~/AutoCompleteWebService.asmx"
MinimumPrefixLength="3" CompletionSetCount="12" DelimiterCharacters=";" OnClientPopulating="ShowProcessImage" OnClientPopulated="HideProcessImage">
</asp:AutoCompleteExtender>
</td>
我创建了一个 web 服务并从自动控制扩展器中调用了这个方法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace TestChart
{
/// <summary>
/// Summary description for AutoCompleteWebService
/// </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 AutoCompleteWebService : System.Web.Services.WebService
{
public AutoCompleteWebService(){
}
[WebMethod]
public string[] GetItemsList(string Prefix,int count)
{
char c1;
char c2;
char c3;`enter code here`
if (count == 0)
{
count = 10;
}
Random rnd =new Random();
List<string> items = new List<string>();
for (int i = 0; i < count; i++)
{
c1 = Convert.ToChar(rnd.Next(65, 90));
c2 = Convert.ToChar(rnd.Next(97, 122));
c3 = Convert.ToChar(rnd.Next(97, 122));
items.Add(Prefix + c1 + c2 + c3);
}
return items.ToArray();
}
}
}
如果我单独运行这个网络服务,它工作正常,但是当我运行项目时,文本框没有显示自动完成选项。
谁能帮我分析错误。
提前致谢