c# - 撕毁我的头发 - ASP.Net AJAX AutoComplete 不工作

标签 c# asp.net-ajax autocomplete

希望有人能帮忙解决这个问题。我一直在网上上下浏览并通过这个网站寻找答案,但仍然无法让自动完成 AJAX 控件工作。我已经从尝试将其包含在现有站点中转变为将其剥离回到非常基本的形式,但它仍然无法正常工作。我使用 Page Methods 而不是本地 Web 服务时比较幸运,所以这是我的代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="droptest.aspx.cs" Inherits="droptest" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>  
    <form id="form1" runat="server">    
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
        </asp:ScriptManager>
        <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" 
            MinimumPrefixLength="1" ServiceMethod="getResults" 
            TargetControlID="TextBox1">
        </cc1:AutoCompleteExtender>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Services;
using System.Web.Services;

public partial class droptest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [WebMethod]
    public string[] getResults(string prefixText, int count)
    {
        string[] test = new string[5] { "One", "Two", "Three", "Four", "Five" };
        return test;
    }
}

试图让事情尽可能简单,但我得到的只是带有页面源的自动完成下拉列表(从 <! doctype... 开始)逐个字母,或者在 IE7 中它只是说“未定义”所有列表的下方。

我目前正在使用 Visual Web Developer 2008,它在本地主机上运行。我想我已经用尽了我能找到的所有“试试这个...”选项,从添加 [ScriptMethod] 到更改 Web.Config 中的所有内容。

这段代码有什么明显的错误吗?

可能唯一会产生影响的其他事情是在 Global.asax 中我做了一个 Context.RewritePath 来重写 URL - 这对 AJAX 有任何影响吗?

感谢您提供的任何帮助。

最佳答案

我认为您还需要将您的页面名称包含在 servicePath 中。

    <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" 
            MinimumPrefixLength="1" ServiceMethod="getResults" ServicePath="droptest.aspx" 
            TargetControlID="TextBox1">
    </cc1:AutoCompleteExtender>

关于c# - 撕毁我的头发 - ASP.Net AJAX AutoComplete 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1306605/

相关文章:

c# - Aspnet MVC 4 验证十进制数

c# - Ado.net Sql 连接

javascript - 访问 JSON 响应中的字段

css - 为背景颜色 : hsla and rgba 启用 VIM 到 CSS 自动完成

java - 如何减少hibernate搜索(lucene)中的结果集?

javascript - 使 Jquery Autocomplete 或 Select2 插件在 knockout foreach 绑定(bind)中工作

c# - 在 .NET 反射中将 GetProperties() 与 BindingFlags.DeclaredOnly 结合使用

c# - C# 中的 RSA 不会为特定 key 生成相同的加密字符串?

c# - 如何清除gridview

asp.net - 更新Panel渲染表行错误