Ajax AutoCompleteExtender-为什么此代码不起作用
本文关键字:代码 不起作用 为什么 AutoCompleteExtender- Ajax | 更新日期: 2023-09-27 18:28:19
使用aspnet 3.5。这是我的密码。是的,我知道我应该使用jquery。
当我在文本框中键入时,什么也没发生。我在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" };
}
尝试将引用从WebMethod和ScriptMethod更改为完全限定名称:
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
在您的参数中,将前缀更改为prefixText(返回类型和参数名称和类型必须完全匹配,包括大小写)
public string[] GetCompletionList(string prefixText, int count)
确保您的脚本管理器在您的页面上。
define your web method as static like
public static string[] GetList(string prefix, int count)
试试这个
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" };
}
}
我尝试从javascript函数调用Web服务,结果成功了。因此,问题在于,不知何故,自动完成并没有获得Web服务的"结果"。
这一页上的所有其他答案要么不适用,要么不起作用。
我认为ajax文档中缺少一些内容。如果我能把它写下来,我会把它写在这里。