2012-03-19 74 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

相关问题