0

我在我的 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();
        }
    }
}

如果我单独运行这个网络服务,它工作正常,但是当我运行项目时,文本框没有显示自动完成选项。

谁能帮我分析错误。

提前致谢

4

3 回答 3

0

你觉得webmethod的签名不对,试试这个(prefixText是必须的,我觉得)

public string[] GetItemsList(string prefixText, int count)
于 2013-10-22T12:17:23.350 回答
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();
        }
于 2013-10-23T10:56:10.927 回答
-1

要允许使用 ASP.NET AJAX 从脚本调用此 Web 服务,请取消注释 asmx 代码隐藏文件中的以下行:

[System.Web.Script.Services.ScriptService]
于 2016-07-08T09:58:46.990 回答