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?
<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>
[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();
}