【发布时间】:2014-02-22 07:39:42
【问题描述】:
我有一个带有 Ajax 控件扩展器的文本框,用于在我的 aspx 页面上自动完成,但我不知道为什么它不起作用。我缺少什么东西吗?顺便说一句,我正在使用 VS 2013。
Default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" DelimiterCharacters="" Enabled="True" ServiceMethod="GetCompletionList" MinimumPrefixLength="1" CompletionInterval="500" TargetControlID="TextBox1" UseContextKey="True">
</asp:AutoCompleteExtender>
</div>
</form>
</body>
</html>
------------------------------------------------------
**Default2.aspx.cs**
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
string[] address = { "Woodlands", "Rochester", "GreenVile" };
return(from a in address where a.StartsWith(prefixText,StringComparison.CurrentCultureIgnoreCase) select a).Take(count).ToArray();
}
}*
【问题讨论】:
标签: c# asp.net ajax autocomplete visual-studio-2013