2

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私は大学のコンピューターを使用しているため、使用しているネットワークのタイプが原因である可能性があると思います。わからない。

どんな助けでも大歓迎です!!

ありがとう。

4

1 に答える 1

0

私はそれを働かせました。これは私がそれを修正した方法です:

私のプロジェクトは、Visual Studio の「Web サイト アプリケーション」でした。単純に「Web サイト」プロジェクトを作成したところ、すべてが完全に機能しました...理由はわかりませんが、機能しました。

したがって、他の誰かが同じ問題を抱えている場合は、コードを「Web サイト アプリケーション」プロジェクトではなく「Web サイト」プロジェクトに移植してみてください。

それが役立つことを願っています。

于 2011-12-28T23:32:15.377 に答える