Click here to Skip to main content
15,917,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have TextBox and an AutoCompleteExtender targeted to this TextBox.
One button is also there. After clicking the button the AutoCompleteExtender is not working. When I remove one line of code (ie.txtTestCode.Focus();) it is working perfectly. But I can't remove this because after clicking the button again it should focus to TextBox. How can I resolve this?

XML
<form id="form1" runat="server">
       <asp:ScriptManager ID="ScriptManager1" runat="server">
       </asp:ScriptManager>
       <div>
           <asp:TextBox ID="txtTestCode" runat="server"></asp:TextBox>
               <cc1:AutoCompleteExtender ID="AutoCompleteExtenderDemo" runat="server"
               TargetControlID="txtTestCode" ServiceMethod="GetCompletionList" EnableCaching="true"
               MinimumPrefixLength="1" CompletionInterval="10"
               CompletionSetCount="5">
               </cc1:AutoCompleteExtender>
           <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
       </div>

   </form>


C#
[System.Web.Services.WebMethod]
    public static string[] GetSuggestions(String prefixText, int count)
    {
        string[] movies = { "BIO", "CYT", "GTT", "HEM", "HTP", "MBI", "PHS", "RGL", "SEM", "SPL", "STL", "URN" };

        ArrayList filteredList = new ArrayList();

        foreach (string s in movies)
        {
            if (s.ToLower().StartsWith(prefixText.ToLower()))
                filteredList.Add(s);
        }
        return (string[])filteredList.ToArray(typeof(string));
    }

    [System.Web.Services.WebMethod]
    public static string[] GetCompletionList(String prefixText, int count)
    {
        string[] suggetions = GetSuggestions(prefixText, count);
        return suggetions;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        txtTestCode.Text = "";
        txtTestCode.Focus();
    }
Posted
Updated 5-Aug-11 4:46am
v4

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900