?
Solved

ontextchanged

Posted on 2011-02-18
10
Medium Priority
?
753 Views
Last Modified: 2012-05-11
using ASP.Net with c#.
I want to filter the gridview data based on what is typed in a textbox. What I am currently doing is as follows: I have a "Filter" Button and it filters the cached data when the button is pressed.
What I want to accomplish is that it should filter as the user types in the textbox. for this I tried using the "OnTextChanged" event, but the user still has to take the focus away from the text box for the filter to kick in.

Is there any way it I can have the filter to work as the user types in the textbox without taking the focus away from the textbox.

Thanks.
0
Comment
Question by:patd1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 668 total points
ID: 34928913
I believe there is an onKeyUp function that might be useful in this context.
0
 

Author Comment

by:patd1
ID: 34929060
ok, that sound promising, but how do i call server side method from javascript?

Thanks.
0
 
LVL 20

Expert Comment

by:informaniac
ID: 34929069
onKeyUp should be a client side event I guess. It won't fire the server event.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 20

Assisted Solution

by:informaniac
informaniac earned 668 total points
ID: 34929184
Ajax.
0
 
LVL 6

Assisted Solution

by:Ramone_Hamilton
Ramone_Hamilton earned 664 total points
ID: 34929319
informaniac is correct, the onkeyup event can be used for this but it is client side only.  You can add it to a textbox in code like the following:

TextBoxName.Attributes.Add("onkeyup", "SomeJavscriptMethod(this)");

Open in new window

0
 

Author Comment

by:patd1
ID: 34929403
I tried onkeyup, it's cool!
But I have to type it too quickly, before it shoots the postback. My users will be freaked out, as they may not be able to type more then one char before it fires, and they have to click again to bring the focus back to the text box. I don't know if I am able to explain it well.

Is there any way I can bring focus back on the text box after each RaisePostBackEvent? so the user can keep typing to narrow down the search?

Thank You.
0
 

Author Comment

by:patd1
ID: 34929440
And I wanted to add that I tried the this.TextBox1.Focus(); in the end of RaisePostBackEvent, but, it sets focus in the begining of the string. How do I put it at the end of the string.

thank you.
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34929441
The trick is to delay.

What I do in this situation is to set a short one-or-two second timeout when the onkeyup event fires, rather than do the search right away on every keystroke.  If there is already a timeout pending, i cancel it and start a new one.  Only when the timer eventually fires (the user has to have stopped typing for one or two seconds) should the actual search be done.

In client-side javascript I use setTimeout and clearTimeout functions.  Not sure how you would do it in your context.
0
 

Author Comment

by:patd1
ID: 34929609
I actually wrote another javascript to set focus on the textbox at the end of the string. It works, but seems to be too slow now.

Will the AJAx solution be faster?

Thanks.
0
 

Author Closing Comment

by:patd1
ID: 34930307
Wonderful!
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question