我用我的ASP.net頁的AJAX自動完成擴展控制文本框:自動完成擴展不能調用Web服務方法
<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();
}
}
}
如果我單獨運行此WebService它的正常工作,但是當我運行文本框中沒有顯示自動完成選項的項目。
任何人都可以幫助我分析錯誤。
在此先感謝
這是一個古老的問題,但我有同樣的問題,我發現參數必須完全命名。在我的情況下,我使用contextKey以及我的Web服務方法如下所示:[WebMethod(),ScriptMethod()] public static string [] GetCompletionListOther(string prefixText,int count,string contextKey)。這基本上是Ankur在對Monika的回答發表評論時所說的。 – shev72