我在ASP.net页面中使用ajax auto complete extender控件来获取文本框:
<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();
}
}
}
如果我单独运行这个web服务它运行正常,但是当我运行项目时,文本框没有显示自动完成选项。
任何人都可以帮我分析错误。
提前致谢
答案 0 :(得分:0)
你认为webmethod的签名是错误的,试试这个(我认为prefixText是必要的)
public string[] GetItemsList(string prefixText, int count)
答案 1 :(得分:0)
使用
[WebMethod]
public string[] GetItemsList(string PrefixText,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(PrefixText + c1 + c2 + c3);
}
return items.ToArray();
}
答案 2 :(得分:-1)
要允许使用ASP.NET AJAX从脚本调用此Web Service,请在asmx代码后面的文件中取消注释以下行:
[System.Web.Script.Services.ScriptService]