ASP.NET OnTextChanged issue 
December 4th, 2008, 03:04 PM
| | Newbie | | Join Date: Dec 2008
Posts: 4
| | |
Hi,
I wonder if anyone has any ideas regarding the following issue I have.
I have a form with multple Textboxes. One of the Textboxes uses 'OnTextChanged' to retrieve information from a database using the information keyed into the Textbox.
My problem is that the user will click or tab to another Textbox, the data is retrieved successfully, but, when the form is available again, the textbox that the user clicked into is not in focus. This means that the user effectively has to click into this textbox twice.
I could set the focus of the next textbox from the ontextchange method, but I don't know which textbox the user actually tried to move into.
| 
December 4th, 2008, 03:38 PM
|  | Forum Leader | | Join Date: Apr 2008 Location: San Antonio, TX (USA)
Posts: 2,569
| | | re: ASP.NET OnTextChanged issue
I don't know if this will help...but you might try using another thread to handle the data transfer. That way it doesn't lock up your GUI thread and miss the click on the textbox you want to enter.
| 
December 4th, 2008, 03:47 PM
| | Newbie | | Join Date: Dec 2008
Posts: 4
| | | re: ASP.NET OnTextChanged issue
Thanks for your reply. I'll give it a go.
| 
December 4th, 2008, 05:04 PM
|  | Site Moderator | | Join Date: Oct 2006 Location: The Great White North :)
Posts: 4,940
Provided Answers: 8 | | | re: ASP.NET OnTextChanged issue Quote:
Originally Posted by insertAlias I don't know if this will help...but you might try using another thread to handle the data transfer. That way it doesn't lock up your GUI thread and miss the click on the textbox you want to enter. | I'm not sure if that will help in this case...since it's an ASP.NET application.
I would be more inclined to say that you should try placing the TextBox in an UpdatePanel so that it can make an asynchronous call back to the server to do it's processing....This will result in a partial page update (just the TextBox in this case).
-Frinny
| 
December 4th, 2008, 05:05 PM
|  | Forum Leader | | Join Date: Apr 2008 Location: San Antonio, TX (USA)
Posts: 2,569
| | | re: ASP.NET OnTextChanged issue
LOL, it's my turn to try reading for a change ;)
| 
December 4th, 2008, 05:54 PM
| | Newbie | | Join Date: Dec 2008
Posts: 4
| | | re: ASP.NET OnTextChanged issue
I've found a way that I can retrieve the name of the control that's received focus (by using a javascript function and storing the control name in a hidden field on the asp page). So I could issue a call to set the focus of this control after I've accessed the database. What I'm not sure about (because of my lack of knowledge of c#) is how to action the event on a control where i've only got a string of it's name. e.g. it the string is "TextBox2" I need to be able to call TextBox2.Focus(). Any ideas on how I can achieve this?
| 
December 4th, 2008, 06:14 PM
|  | Moderator | | Join Date: Mar 2007 Location: Canada
Posts: 757
| | | re: ASP.NET OnTextChanged issue
I'll be interested to hear how you overcome this as I have the same problem in another application that I've not gotten as far as attempting to fix yet. So you might save me trying to figure out a fix for it :)
| 
December 4th, 2008, 07:01 PM
|  | Site Moderator | | Join Date: Oct 2006 Location: The Great White North :)
Posts: 4,940
Provided Answers: 8 | | | re: ASP.NET OnTextChanged issue Quote:
Originally Posted by AndrewK I've found a way that I can retrieve the name of the control that's received focus (by using a javascript function and storing the control name in a hidden field on the asp page). So I could issue a call to set the focus of this control after I've accessed the database. What I'm not sure about (because of my lack of knowledge of c#) is how to action the event on a control where i've only got a string of it's name. e.g. it the string is "TextBox2" I need to be able to call TextBox2.Focus(). Any ideas on how I can achieve this? | I used this technique in one of my web applications as well.
Did you try the UpdatePanel?
I'd be interested in knowing if that works....
| 
December 6th, 2008, 10:35 AM
| | Newbie | | Join Date: Dec 2008
Posts: 4
| | | re: ASP.NET OnTextChanged issue
Thanks for all your help. Just to let you know that I've actually gone for the asynchronous callback route which seems okay so far, and much slicker for the user. However, one thing to be aware of, which caught me out, is that if you set the 'value' on readonly fields, the data gets lost on postbacks. I ended up changing them to enabled=false instead.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,689 network members.
|