Dav*_*ave 2 c# autocomplete asp.net-ajax
希望有人能帮忙解决这个问题.我一直在网络上,并通过这个网站寻找答案,但仍然无法使Autocomplete AJAX控件工作.我试图将它包含在一个现有的网站中,直接将其剥离回一个非常基本的形式,但它仍然无法运行.我使用页面方法而不是本地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;
}
}
Run Code Online (Sandbox Code Playgroud)
试图让事情变得尽可能简单,但我得到的只是自动完成下拉列表与页面来源(以<! doctype...字母开头),或者在IE7中它只是在列表中一直显示"未完成".
我目前正在使用Visual Web Developer 2008,它在Localhost上运行.我想我已经筋疲力尽了所有可以找到的"试试这个..."选项,从添加[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>
Run Code Online (Sandbox Code Playgroud)