Connecting Tech Pros Worldwide Help | Site Map

ASP.NET OnTextChanged issue

Newbie
 
Join Date: Dec 2008
Posts: 4
#1: Dec 4 '08
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.
insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#2: Dec 4 '08

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.
Newbie
 
Join Date: Dec 2008
Posts: 4
#3: Dec 4 '08

re: ASP.NET OnTextChanged issue


Thanks for your reply. I'll give it a go.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,075
#4: Dec 4 '08

re: ASP.NET OnTextChanged issue


Quote:

Originally Posted by insertAlias View Post

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
insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#5: Dec 4 '08

re: ASP.NET OnTextChanged issue


LOL, it's my turn to try reading for a change ;)
Newbie
 
Join Date: Dec 2008
Posts: 4
#6: Dec 4 '08

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?
balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Posts: 757
#7: Dec 4 '08

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 :)
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,075
#8: Dec 4 '08

re: ASP.NET OnTextChanged issue


Quote:

Originally Posted by AndrewK View Post

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....
Newbie
 
Join Date: Dec 2008
Posts: 4
#9: Dec 6 '08

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.
Reply

Tags
asp.net, c#.net, ontextchanged, textbox