c# - 具有自动完成功能的文本框

标签 c# asp.net entity-framework autocomplete ajaxcontroltoolkit

我正在使用 Visual Studio 2008 进行编程,并使用 .NET Framework 3.5 和 C# 制作 Web 应用程序。所有 DAL 都与一个强大的 Entity Framework 包装器(类似于 VS.net 2010 将使用的包装器)链接。我有一个用于搜索名字和姓氏的文本框。我遇到的问题是我正在使用 AJAX Control Toolkit 2.0,它提供了一个自动完成扩展器,但是通过使用 WebServices (asmx)。有没有其他方法可以在不使用网络服务的情况下使用自动完成功能?

问候,

西蒙

P.s.:抱歉我的英语不好,我尽力了:)!

最佳答案

您不需要实现单独的网络服务来提供具有自动完成功能的文本框,但是,您确实需要为自动完成扩展器提供有效的 Web 方法,它可以用来调用以检索匹配条目的列表。

AutoComplete Extender 控件的 AutoComplete 功能的关键属性是 ServiceMethod 和 ServicePath 属性。 ServiceMethod 指定 AJAX 框架调用的 web 方法 的名称,以检索自动完成下拉列表的匹配项,ServicePath 属性指定将包含的文件的完整路径和文件名ServiceMethod 属性的方法。但是请注意,ServicePath 属性是可选的。

如果省略 ServicePath 属性,AJAX 框架将尝试在文本框和自动完成扩展程序所在的实际网页中的代码中查找 ServiceMethod Web 方法。这通常位于“代码隐藏”文件中。

来自AutoComplete Sample页:

  • ServiceMethod - The web service method to be called. The signature of this method must match the following:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetCompletionList(string prefixText, int count)
{ ... }

Note that you can replace "GetCompletionList" with a name of your choice, but the return type and parameter name and type must exactly match, including case.

  • ServicePath - The path to the web service that the extender will pull the word\sentence completions from. If this is not provided, the service method should be a page method.

关于c# - 具有自动完成功能的文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1188343/

相关文章:

c# - I可查询。比较运算符(== 和 >=)的细节

asp.net - 迁移对 ASP.NET 的 Access

javascript - javascript 中的 ASP.NET Core ViewData 访问

sql-server - Azure Functions - 如何连接到本地 SQL Server Express 数据库?

c# - 在依赖类型上找不到导航属性

c# - 整数方法总是返回 "-1"?

c# - 根据 asp.net 中的哪个用户显示内容

c# - C# 中的文件路径问题(主页

c# - 如何在 Windows 服务 C# 中设置一个 tcplistener

c# - 从后面的代码调用 jquery