0

default1.aspx ページで使用されるコントロールで、asp.net のオートコンプリート jquery を使用したいと考えています。私のコントロールは、登録フォルダーにある searchinput.ascx です。私の問題は、searchinput コントロールのコード ファイルに Web メソッド (getmylist) を記述したことです。しかし、そのメソッドは決して呼び出されません。誰でも私を助けることができます

4

3 に答える 3

0

次のようなWebメソッドを作成します。

 [WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string[] GetPatientFirstName(string prefix)
{
    List<string> customers = new List<string>();
    using (SqlConnection conn = new SqlConnection())
    {
        string connectionstring = CCMMUtility.GetCacheForWholeApplication();
        conn.ConnectionString = connectionstring;
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "select distinct top(10) PatientFirstname from tblMessage where  " +
            "PatientFirstname  like '%'+ @SearchText + '%' order by PatientFirstname";
            cmd.Parameters.AddWithValue("@SearchText", prefix);
            cmd.Connection = conn;
            conn.Open();
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    customers.Add(string.Format("{0}", sdr["PatientFirstname"]));
                }
            }
            conn.Close();
        }
        return customers.ToArray();
    }
}

ここにhtmlコードがあります:

   $(document).ready(function () {
        $('[ID$=txtPatientFirstname]').live('keyup.autocomplete', function () {

            $(this).autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: '<%=ResolveUrl("~/Resources/WebService.asmx/GetPatientFirstName") %>',
                        data: "{ 'prefix': '" + request.term + "'}",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        success: function (data) {
                            response($.map(data.d, function (item) {
                                return {
                                    label: item.split('-')[0],
                                    val: item.split('-')[1]
                                }
                            }))
                        },
                        error: function (response) {
                            alert(response.responseText);
                        },
                        failure: function (response) {
                            alert(response.responseText);
                        }
                    });
                },
                select: function (e, i) {
                },
                minLength: 1
            });
        });
});

これは実際の例です......これがあなたの問題を解決することを願っています。

于 2012-11-01T13:46:28.330 に答える
0

Jquery website

You can find wat you need there for a start. Also, show your ajax call so that I can try helping on y it is not working. Your approach of writting a web method and making a ajax call from the jquery auto complete should work out fine otherwise.

于 2012-11-01T13:27:55.750 に答える
0

コードなしで解決するのは難しいですが、いくつかの一般的な原因が考えられます:

  • ClientID 値を正しく使用していません - asp.net コントロールは、デザイナーと同じように実際のマークアップに同じ ID を持っていません

  • Web メソッドにエラーがあります - f12 を押して Web 開発者ツールバーを開き、[NET] タブに移動して (少なくとも Firefox では)、500 エラー コードまたは類似のものが返されているかどうかを確認してください。

于 2012-11-01T13:38:53.760 に答える