Click here to Skip to main content
15,891,621 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CSS
I have text box and gridview:

aspx page:

<asp:TextBox ID="txtsearch" runat="server" OnTextChanged="search" AutoPostBack="true"> </asp:TextBox>

aspx.cs:

Protected void search(object sender, eventargs e)

{

//here i am binding gridview stuff.

}

gridview:

name id

rau     1

rahul   2

mash   3

christ   4

everything works fine. but, when i typing name for example: mash. it is not retrieving or it is not calling that search function. when i give tab or leave from textbox, it is invoking search function.

but i need while typing 'm' itself , it should invoke the search function. i mean by automatically it shoud invoke when we type text inside the textbox not after leaving or tab from textbox. how to solve this problem. help needed.
Posted
Comments
King Fisher 19-Dec-13 1:13am    
check out

There is no server side event for character typed - TextChanged is only signaled when the textbox focus is lost.

But in all seriousness, you probably don't want to do that.

The reason is that it would mean a postback going from the client to the server on very key, followed by a search at the server, and a page load back to the client - which will respond in it's own time.

If the user is happy to type a character, wait, type a character, wait, type a character,... then you will be ok, but for most users that would be an annoying exercise in frustration.

Try looking at doing your search locally to the client in the javascript instead.
 
Share this answer
 
you are observing this behavior because the search is called on "OnTextChanged" event, the value of text box gets changed when you focus is moved out of the control.

Try registering the event with the use of Jquery on your text box (please check which one suits KeyPress or KeyUp)
 
Share this answer
 
TextBox server control doesn't raise event on each key stroke, rather the event gets fired only after losing the control focus.

Try doing the below in order to solve your problem
from the client side, onKeyUP event call _postback() method !!
 
Share this answer
 
hi thanks for reply..

so i need help how to use here javascript or jquery function in this situation.
 
Share this answer
 
Comments
Jashobanta 18-Dec-13 16:40pm    
check my answer..
You will need a javascript or Jquery code to do that. And the corresponding event should be on key up.

JavaScript
$(#txtSearch).keyUp(function()
{
        var textVal=$(#txtSearch).val();
        alert(' searching for '+textVal);
]);


I can provide you a full working code if you want it.. but this already solves I guess... and best way to check is, you can check here itself in CodeProject. As you keep on commenting, you can see that the preview is created on text changed event.. Simple like that.

Regards
Jashobanta
 
Share this answer
 
go to the edit template in Grid view and select your column name ,then you will get the textbox over there and double click the textbox,you will get the textchange event


XML
<pre lang="cs">protected void txtSearch_TextChanged(object sender, EventArgs e)
   {
your code here
   }</pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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