I have a Textbox that changes the content of a dropdown in the OnTextChanged event. This event seems to fire when the textbox loses focus. How do I make this happen on the keypress or keyup event?
Here is an example of my code
<asp:TextBox ID="Code" runat="server" AutoPostBack="true" OnTextChanged="Code_TextChanged">
<asp:UpdatePanel ID="Update" runat="server">
<ContentTemplate>
<asp:DropDownList runat="server" ID="DateList" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Code" />
</Triggers>
</asp:UpdatePanel>
So in the codebehind, I bind the dropdown on page load. The Code_TextChanged event just rebinds the dropdown. I would like this to happen on each keypress rather than when the textbox loses focus.
I inherited this code recently and this is not the ideal method of doing this for me, but time limitations prevent me from rewriting this in a web servicy method.
I have tried using jQuery to bind the "keyup" event to match the "change" event for the textbox, but this only works on the first key pressed.
This will solve your problem. Logic is same as the solution suggested by Kyle.
Have a look at this.
Code behind goes like this...
I have added additional textbox to see change in action, do remove the textbox.
Would this help you?
How to make an ASP.NET TextBox fire it's onTextChanged event fire in an AJAX UpdatePanel?
Here is a simple way to do it with javascript, an update panel, gridview, sqldatasource and a textbox. As you type it searches the table and displays the results. Short and sweet, no code behind.
I use a javascript trick for trigger a OnTextChanged event, i call a blur function and than re-focus the input text (or, if you have many input text, switch focus from two input text)
I have test it in IE and Firefox.
javascript code:
aspx code
The c# function "GridProdotto_SelectedIndexChanging" retrive data from database and build the grid.