ASP.NET OnTextChanged issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AndrewK
    New Member
    • Dec 2008
    • 16

    ASP.NET OnTextChanged issue

    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.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    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.

    Comment

    • AndrewK
      New Member
      • Dec 2008
      • 16

      #3
      Thanks for your reply. I'll give it a go.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        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....T his will result in a partial page update (just the TextBox in this case).

        -Frinny

        Comment

        • Curtis Rutland
          Recognized Expert Specialist
          • Apr 2008
          • 3264

          #5
          LOL, it's my turn to try reading for a change ;)

          Comment

          • AndrewK
            New Member
            • Dec 2008
            • 16

            #6
            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?

            Comment

            • balabaster
              Recognized Expert Contributor
              • Mar 2007
              • 798

              #7
              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 :)

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                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....

                Comment

                • AndrewK
                  New Member
                  • Dec 2008
                  • 16

                  #9
                  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.

                  Comment

                  Working...