AutoCompleteExtender控件出现undefined和null现象

近日研究ajax control toolkit 在使用AutoCompleteExtender自动输入完成控件时发现一个问题,也许这是微软的一个bug吧。如果返回的数组是纯数字,那么将变成undefined(非0情况)或null(0为null)。

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
    {       
         string[] s = new string[3];

        for (int i = 0; i < 3; i++)
        {
            s[i] = i.ToString();
        }

         return s;   
    }
在上面情况下,将返回:null,undefined,undefined,如果我们改成

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
    {       
         string[] s = new string[3];        
        s[0] = "中文";
        s[1] = "abc";
        s[2] = "123abc";        
         return s;   
    }
那么将返回真确的值。
我还不清楚为什么数字字符串会变成undefined和null,也许是和javascript定义有关系吧!

原文地址:https://www.cnblogs.com/ami/p/904202.html