AutoCompleteExtender
で AjaxControlToolkitの を使用していTextBox
ます。
簡単に言うと、AutoCompleteExtender
ツールを TextBox にドラッグ アンド ドロップし、[オートコンプリート ページ メソッドの追加] をクリックすると、次のエラーが表示されます。
CodeBehind または CodeFile が見つからないため、ページ メソッド "GetCompletionlist を作成できません!
エラーをグーグルで調べた後、基本的に AutoCompelte.asmx という独自の Web サービスを作成しました。以下は、そのクラスのコードです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace AutoCompleteTest
{
/// <summary>
/// Summary description for AutoComplete
/// </summary>
[WebService(Namespace = "http://microsoft.com/webservices/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService
{
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
// Create array of movies
string[] movies = { "Star Wars", "Star Trek", "Superman", "Memento", "Shrek", "Shrek II" };
// Return matching movies
return (from m in movies where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
}
}
}
もちろん、上記はダミー データです..後で、データベースからデータを取得します。
私の Default.aspx は次のようになります。
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
From
<asp:TextBox ID="txtFrom" runat="server">
</asp:TextBox>
<asp:AutoCompleteExtender runat="server"
ID="txtFrom_AutoCompleteExtender"
TargetControlID="txtFrom"
ServiceMethod="GetCompletionList"
ServicePath="AutoComplete.asmx"
MinimumPrefixLength="2"
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="20"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true">
</asp:AutoCompleteExtender>
Web サイトを実行して....テキスト ボックスに入力しても、何も起こりません。エクステンダーは表示されません。「スター」と入力しても。
何が欠けているのですか?なぜ最初にそのエラーが発生したのですか?
PS私は大学のコンピューターを使用しているため、使用しているネットワークのタイプが原因である可能性があると思います。わからない。
どんな助けでも大歓迎です!!
ありがとう。