You have to use autopostback, or (faster) ajax like this:
<asp:TextBox runat="server" ID="txtFilter" autocomplete="off" ></asp:TextBox>
<asp:LinkButton runat="server" ID="lbFilter" onclick="FilterDropdown" Text="filter" style="visibility:hidden;"></asp:LinkButton>
<asp:ScriptManager runat="server" ID="scrMang"></asp:ScriptManager>
<asp:UpdatePanel ID="updSelction" runat="server">
<ContentTemplate>
<asp:ListBox runat="server" ID="ddl" ></asp:ListBox>
</ContentTemplate>
<Triggers >
<asp:AsyncPostBackTrigger ControlID="lbFilter" />
</Triggers>
</asp:UpdatePanel>
public partial class _Default : System.Web.UI.Page
{
string[] Names = {"Andreas",
"Benjamin",
"Caroline",
"Daniel",
"Emil",
"Franziska",
"Gustav",
"Hans"
};
protected void Page_Load(object sender, EventArgs e)
{
txtFilter.Attributes.Add("onkeyup", "__doPostBack('" + lbFilter.UniqueID + "','');");
if(!IsPostBack) {
foreach(var name in Names) {
ddl.Items.Add(name);
}
}
}
protected void FilterDropdown(object sender, EventArgs e) {
ddl.Items.Clear();
foreach(var name in Names) {
if(name.ToLower().Contains(txtFilter.Text.ToLower())) {
ddl.Items.Add(name);
}
}
txtFilter.Focus();
if(ddl.Items.Count >0)
ddl.Items[0].Selected = true;
}
}