2012-02-21 56 views
0

我使用了Ajax的自動擴展的代碼是這樣的web服務的自動完成功能擴展不工作

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> 
    </asp:ToolkitScriptManager> 
    <div> 
    <asp:TextBox ID="txt_AutoComplete" runat="server" Width="200"></asp:TextBox> 
    <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1" 
    ServiceMethod="GetNames" ServicePath="~/AutoComplete.asmx" TargetControlID="txt_AutoComplete"> </asp:AutoCompleteExtender> 

和Web服務Autocomplete.asmx是Web服務並不是要求

[WebMethod] 

     public string[] GetNames(string prefixText, int count) 
     { 
      ArrayList sampleList = new ArrayList(); 

      sampleList.Add("ABC"); sampleList.Add("Hello"); 

      sampleList.Add("Hi"); 

      sampleList.Add("Hey"); 

      ArrayList filteredList = new ArrayList(); 
      foreach (string s in sampleList) 
      { 

       if (s.ToLower().StartsWith(prefixText.ToLower())) 

        filteredList.Add(s); 

      } 
      return (string[])filteredList.ToArray(typeof(string)); 

     } 

但AJAX自動延長工作不

+0

它是否給一個錯誤?什麼?請顯示您的asmx.cs的完整代碼 – Shai 2012-02-21 13:43:08

+0

該方法不起作用 其不調用網絡方法 – 2012-02-21 13:44:19

+0

它根本不調用Web方法? – Shai 2012-02-21 13:45:14

回答

0

u必須使用上面烏爾所需的方法如下

[System.Web.Services.WebMethod]

[System.Web.Script.Services.ScriptMethod]

相關問題