【问题标题】:AutoCompleteExtender doesn't work自动完成扩展器不起作用
【发布时间】:2014-05-09 19:59:25
【问题描述】:

我想用AutoCompleteExtender

但是不行,我在web服务中放了一个断点,但是没有进入web服务!!

<asp:TextBox ID="txt_empName" runat="server" Width="300px" ></asp:TextBox>
                                        <cc1:AutoCompleteExtender ID="txt_empName_AutoCompleteExtender" runat="server"
                                            CompletionListCssClass="autocomplete_completionListElement" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
                                            CompletionListItemCssClass="autocomplete_listItem" Enabled="True" MinimumPrefixLength="4"
                                            OnClientItemSelected="get_emp_num" UseContextKey="True" ServiceMethod="Get_Emp_AutoComplete"
                                            ServicePath="~/EmpAutoComplete.asmx" TargetControlID="txt_empName" BehaviorID="ACE_empName"
                                            EnableCaching="False">
                                        </cc1:AutoCompleteExtender>

我的网络服务:

[WebService(Namespace = "http://tempuri.org/")]
[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
{
    [WebMethod]
    public List<string> Get_Emp_AutoComplete(string prefixText, int count, string contextKey)
    {
        //split the string in the text box to get the department equivalent to the last prefix text entered in the textbox after ',' or ';'
        string[] s = prefixText.Split(new string[] { ",", ";" }, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length > 0)
        {
            prefixText = s[s.Length - 1].Trim();//Last item in the array
        }
        List<string> Emp_List = Get_RequestEmp(prefixText, contextKey);

        return Emp_List;
    }


    public static List<string> Get_RequestEmp(string prefixText, string contextKey)
    {
        prefixText = prefixText.Trim().Replace(' ', '%');
        DBConnection ConnectionObj = new DBConnection(CMSession.GetSession("code", HttpContext.Current), false);

        string  cmdText = "SELECT emp_num , trim(name) FROM grrt5emp WHERE name LIKE '%" + prefixText + "%' ORDER BY name";

        DataTable dt = ConnectionObj.Return_DataTable(cmdText);

        List<string> Emp_List = new List<string>();

        for (int i = 0; i < dt.Rows.Count; i++)
        {

            //Returning key-value pair
            Emp_List.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i][1].ToString(), dt.Rows[i][0].ToString()));
        }
        return Emp_List;
    }

}

我的 AjaxToolkit 版本是:

3.0.30930.28736

【问题讨论】:

  • 可能.Net版本不匹配?
  • @huseyintugrulbuyukisik:那你能给我正确的版本吗

标签: asp.net ajax web-services autocomplete ajaxcontroltoolkit


【解决方案1】:

这对我有用:https://www.c-sharpcorner.com/UploadFile/57a357/autocomplete-extender-in-Asp-Net/ 我认为您只是缺少asp:ScriptManager

【讨论】:

  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-18
  • 2013-11-06
  • 1970-01-01
  • 2012-10-05
  • 2012-12-22
相关资源
最近更新 更多