我正在尝试为文本框实现自动建议。我检查了其他帖子似乎对我没有任何作用。我在 Web 应用程序和网站中都尝试过。请找出我的代码中的错误。当我在文本框中输入字母时什么都没有发生。我可以在浏览器中看到网络服务结果。
删除.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Delete.aspx.cs"
Inherits="WebApplication2.Delete" %>
<%@ Register TagPrefix="ajaxToolkit" Namespace="AjaxControlToolkit"
Assembly="AjaxControlToolkit"%>
<!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 id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true"
EnablePartialRendering="true"
runat="server">
</asp:ScriptManager>
<asp:TextBox ID="myTextBox" runat="server" Width="400px" ></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1"
TargetControlID="myTextBox"
ServiceMethod="Information"
ServicePath="~/WebService1.asmx"
OnClientItemOut="Information"
MinimumPrefixLength="1"
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="5"
ShowOnlyCurrentWordInCompletionListItem="true">
</ajaxToolkit:AutoCompleteExtender>
</div>
</form>
</body>
webservice1.asmx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebApplication2
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class WebService1 : System.Web.Services.WebService
{
[System.Web.Services.WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[]Information(string prefixText)
{
RDFEntities db = new RDFEntities();
var allrows = from s1 in db.RDFMatch_v where s1.RIC.StartsWith(prefixText) select s1.RIC;
return allrows.ToArray();
}
}
}