2012-03-19 81 views
1

使用aspnet 3.5。這是我的代碼。是的,我知道我應該使用jQuery。Ajax AutoCompleteExtender - 爲什麼此代碼無法工作?

當我輸入文本框時沒有任何反應。我在web服務中有一個斷點,它沒有被擊中。

我在做什麼錯?

<asp:TextBox ID="tbName" runat="server" ></asp:TextBox> 
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" 
    TargetControlID="tbName" 
    ServiceMethod="GetList" ServicePath="wsWebServices.asmx" 
    MinimumPrefixLength="2"> 
</cc1:AutoCompleteExtender> 

[WebMethod] 
[ScriptMethod] 
public string[] GetList(string prefix, int count) 
{ 
    return new string[] { "abc", "def", "hij", "abc", "def", "hij", "abc", "def", "hij", "abc", "def", "hij" }; 
} 
+0

你檢查了我的答案嗎? – 2012-03-28 17:24:52

回答

0

我試着從javascript函數調用webservice並且工作。所以這個問題在某種程度上是因爲自動完成並沒有選擇web服務的「結果」。

此頁面上的所有其他答案都不適用或無效。

我認爲ajax文檔中缺少一些東西。如果我能做到這一點,我會在這裏寫下來。

0
define your web method as static like 
public static string[] GetList(string prefix, int count) 
+0

沒有什麼區別。此外,我將一個管道連接起來,我打算做一個數據庫調用,所以我無法使用靜態。 – TheMoot 2012-03-30 14:59:55

2

嘗試改變到完全合格的名稱來自的WebMethod和ScriptMethod引用:

[System.Web.Services.WebMethod] 
[System.Web.Script.Services.ScriptMethod] 

在參數變化前綴prefixText(返回類型和參數名稱和類型必須完全匹配,包括案例)

public string[] GetCompletionList(string prefixText, int count) 

確保您的腳本管理器在您的頁面上。

+0

完全限定名稱並沒有幫助。我不知道你爲什麼說要使用prefixText而不是前綴。我在C#中編寫代碼。 – TheMoot 2012-03-30 14:57:47

+0

@TheMoot這就是它從ASP.NET網站直接說明的。 「請注意,您可以用您選擇的名稱替換」GetCompletionList「,但返回類型和參數名稱和類型必須完全匹配,包括大小寫。」 - http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx – 2012-03-30 15:01:31

+0

@TheMoot我會嘗試在ASP.NET網站上所述的prefixText。 – 2012-03-30 15:01:57

0

試試這個

ASPX

<asp:TextBox ID="tbName" runat="server" autocomplete="off" ></asp:TextBox> 

<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" 
    TargetControlID="tbName" 
    ServiceMethod="GetList" 
    ServicePath="wsWebServices.asmx" 
    MinimumPrefixLength="2"> 
</cc1:AutoCompleteExtender> 

在服務 檢查您的ASMX路徑太 上述類把 [System.Web.Script.Services.ScriptService] 公共類wsWebServices: System.Web.Services.WebService {

[WebMethod] 
    public string[] GetList(string prefix, int count) 
    { 


return new string[] { "abc", "def", "hij", "abc", "def", "hij", "abc", "def", "hij", "abc", "def", "hij" }; 
    } 
} 
+0

對不起。我不明白你在這裏說什麼。你的aspx和我的一樣。你的web服務有什麼不同? – TheMoot 2012-03-30 14:16:14

相關問題