0

我想使用 AjaxToolkit AutoCompleteExtender。我的 WebService 被触发,如果我在返回的值上放置一个断点,我可以看到有数据被返回。但是,AutoCompleteExtender 不显示结果。

我读过这个 stackoverflow 线程:AutoCompleteExtender 正在触发,webservice 正在返回结果,但这些没有被显示

但是,这个答案并不能解决我遇到的问题。

这是我的代码:

ASPX

<asp:ToolkitScriptManager ID="asm" runat="server" EnablePageMethods="true" EnablePartialRendering="true"></asp:ToolkitScriptManager>
<asp:UpdatePanel ID="upApprovedBy" runat="server">
    <ContentTemplate>
        <asp:TextBox id="txtApprovedBy" runat="server" AutoComplete="Off"></asp:TextBox>
        <asp:AutoCompleteExtender 
            runat="server" 
            ID="ac_txtApprovedBy"  
            CompletionInterval="500"
            TargetControlID="txtApprovedBy"
            ServiceMethod="SearchWinUsers"
            CompletionSetCount="20"                                                                                                                         
            MinimumPrefixLength="2" 
        >
        </asp:AutoCompleteExtender>
    </ContentTemplate>
</asp:UpdatePanel>

ASPX.CS

[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static string[] SearchWinUsers(string prefixText, int count)
{
    logic common = new logic();
    string[] SelectedApprovers = new string[0];
    try
    {
        DataTable dt = new DataTable();
        string sql = "SELECT TOP(" + count + ") FirstName + ' ' + LastName AS DisplayName FROM USERSTABLENAME WHERE (IsDeActivated = 0) AND ((FirstName LIKE '%" + prefixText + "%') OR (LastName LIKE '%" + prefixText + "%')) ORDER BY FirstName";
        dt = common.getDataTable(sql);
        SelectedApprovers = new string[dt.Rows.Count];
        int i = 0;
        foreach (DataRow dr in dt.Rows)
        {
            SelectedApprovers.SetValue(dr["DisplayName"].ToString(), i);
            i++;
        }
        dt.Dispose();
    }
    catch (Exception ex)
    {
        common.alert("Error in page.location.<br>ERROR=" + ex.Message);
    }

    return SelectedApprovers;
}

任何建议,将不胜感激!

我应该提到,我的 ASPX 片段中的代码位于此层次结构中:Page > TabContainer > TabPanel > FormView > THIS CODE LIVES HERE

4

1 回答 1

0

Got it to work finally!!!

I moved the webservice out of the *.ASPX.CS to an *.ASMX

That resolved the issue I was having.

If you're having the same problem, checkout this tutorial. It got me going in the right direction!

http://www.codeproject.com/Articles/201099/AutoComplete-With-DataBase-and-AjaxControlToolkit#

于 2012-07-03T21:04:56.667 回答