ASP.Net Textchanged Text Box

I have a webpage. I show entries from a table of, say, students on my page. I ask all the students and show them in the grid. I want to use a text box to filter the results of a datagridview. For example, if the user types a in the text box, the grid will only show students who have an “a” in his / her name. I want to update the grid while editing a text field.

I set the autopostback textbox property to true, and I am updating the grid in the event with text change text. But the textchanged event fires only after the text field loses focus. How can I run it after custom types of just one character? thanks.

+4
source share
5 answers

You must use the onKeyDown event. However, I would suggest using ASP.NET AJAX or jQuery to load results using Ajax.

Here is one example from asp.net: http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx

Another one, from the Code project: http://www.codeproject.com/Articles/38803/Google-Like-Search-TextBox

+4
source

You might want to show some of your real code if there is any specific method you want to go with. Otherwise, you are going to get people to tell you how they will do it.

Now does it look something like this?

<asp:Textbox id="myTextbox" runat="server" onChange="txtChanged" AutoPostBack="true"/> public void txtChanged(object sender, EventArgs e) { //Get text from textbox string text = ((TextBox)sender).Text; //Do what ever it is you want to do to edit the text text = text.ToUpper(); //Update the other textbox with this text txtMyText2.Text = text; } 
+2
source

I think the best and cleanest way is to use Rad Controls, here is an example of how to do it: http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandcombo/defaultcs.aspx?product= grid

+1
source

You can use PicNet for this in the Client, and not for a more convenient user. You can find it here http://www.picnet.com.au/resources/tablefilter/demo.htm Remember that Gridview is displayed as an HTML table, so you can freely use this jQuery plugin.

Good luck

0
source

The TextChanged event is TextChanged only when a request is sent to the server. If you want to fire an event or make a function when the text inside the text field changes, use the OnKeyDown event (right with Schiavini).

0
source

Source: https://habr.com/ru/post/1396417/


All Articles