sd_dracula
sd_dracula

Reputation: 3896

ajaxtoolkit AutoCompleteExtender not working

Trying to get an autocomplete to work an a textbox but it seems that the code behind method is never firing. Can anyone see the issue from below? I have tried various samples/tutorials to no effect.

<asp:ScriptManager ID="SM1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel" runat="server">
        <ContentTemplate>
            <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
            <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtUserName" ServiceMethod="GetCompletionList"
            MinimumPrefixLength="2" CompletionInterval="10" EnableCaching="true" CompletionSetCount="3" UseContextKey="True">
            </ajaxToolkit:AutoCompleteExtender>
        </ContentTemplate>
    </asp:UpdatePanel>

code behind:

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethod()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
   string connectionString = ConfigurationManager.ConnectionStrings["WMSDatabase"].ConnectionString;
   SqlConnection conn = new SqlConnection(connectionString);
   // Try to use parameterized inline query/sp to protect sql injection
   SqlCommand cmd = new SqlCommand("SELECT TOP " + count + " Alias FROM dbo.Users WHERE Alias LIKE '" + prefixText + "%'", conn);
   SqlDataReader oReader;
   conn.Open();
   List<string> CompletionSet = new List<string>();
   oReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
   while (oReader.Read())
   CompletionSet.Add(oReader["Alias"].ToString());
   return CompletionSet.ToArray();
}

Upvotes: 0

Views: 5716

Answers (1)

Kapil Khandelwal
Kapil Khandelwal

Reputation: 16144

Try removing the update panel from your code:

<asp:ScriptManager ID="SM1" EnablePageMethods="true" runat="server"></asp:ScriptManager>
            <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
            <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtUserName" ServiceMethod="GetCompletionList"
            MinimumPrefixLength="2" CompletionInterval="10" EnableCaching="true" CompletionSetCount="3" UseContextKey="True">
            </ajaxToolkit:AutoCompleteExtender>

Upvotes: 2

Related Questions