Click here to Skip to main content
13,090,299 members (77,167 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a textbox and an autocomplete extender. The Code is executing perfectly. But I want open the list as and when I focus on the textbox.

Please suggest.
I used all these code.
<asp:TextBox ID="TextBox3" runat="server" Width="268px"                   ontextchanged="TextBox3_TextChanged" AutoPostBack="true" onblur="Change(this, event)" onfocus="Change(this, event)"></asp:TextBox>
<ajax:autocompleteextender ID="AutoCompleteExtender1"  runat="server" TargetControlID="TextBox3" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="10" ServiceMethod="GetCountries"
CompletionListCssClass="autocomplete_completionListElement"                 CompletionListItemCssClass="autocomplete_listItem"                CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem">

    public static List<string> GetCountries(string prefixText)
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString.ToString());
        SqlCommand cmd = new SqlCommand("select * from table1 where col1 like @id+'%'", con);
        cmd.Parameters.AddWithValue("@id", prefixText);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        List<string> CountryNames = new List<string>();
        for (int i = 0; i < dt.Rows.Count; i++)
        return CountryNames;

please help me.
My question is "How to open the list of autocompleteextender, when my cursor focus the textbox".
Please help
Posted 21-Dec-12 9:53am
Updated 22-Dec-12 18:18pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
        AutoCompleteExtender1.ContextKey = "ace1";
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
        string[] result = new string[6];
        for (int i = 0; i < 6; i++)
            result[i] = prefixText + i.ToString();
        return result;


<html xmlns="" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>


    <form id="form1" runat="server">
    <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <ajaxToolkit:AutoCompleteExtender MinimumPrefixLength="0" ID="AutoCompleteExtender1"
            ServiceMethod="GetCompletionList" runat="server" TargetControlID="TextBox1">

You can certainly have a reference from it, like MinimumPrefixLength="0"
Source : ASP .NET Forum[^]
Sourav Sarkar-SS2 22-Dec-12 12:27pm
Its opening the list at keydown but in keyup its getting hidden.
So no use of it.
please suggest any other ways

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 23 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100