How can I get my Autocomplete extender to work?

前端 未结 6 1636
醉酒成梦
醉酒成梦 2021-01-21 10:49

I\'ve tried to the letter to search for mistakes in my code, but i can\'t myself get that autocomplete extender to work. Help wanted.

Here\'s my code: (excerpt from my

6条回答
  •  失恋的感觉
    2021-01-21 11:19

    As well as the GetCompletionList method being incorrectly declared as static, it needs to have two attributes; [System.Web.Services.WebMethod] and [System.Web.Script.Services.ScriptMethod]

    So your declaration should look like this:

    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public string[] GetCompletionList(string prefixText, int count) { ...
    

    Also your service class should have the following attributes:

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    

    The autocomplete extender will also appear to be broken if your GetCompletionList method throws an exception. To guard against this you should add a try..catch block around the code the function

    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public string[] GetCompletionList(string prefixText, int count)
    {
        List returnData = new List();
    
        try
        {
            // database access code that sets returnData
        }
        catch (Exception ex)
        {
            // log the exception
        }
    
        return returnData.ToArray();
    }
    

提交回复
热议问题