Text Box Loses Focus on AsyncPostback

Last post 08-07-2008 9:57 AM by CallMeLaNN. 9 replies.

Sort Posts:

  • Text Box Loses Focus on AsyncPostback

    07-21-2008, 11:45 AM
    • Loading...
    • ataxia1
    • Joined on 05-01-2007, 3:16 PM
    • Posts 107

    Our application has a form and a list on the same page.  Many users make updates, so the list uses a timer to refresh every thirty seconds.  My problem is that if someone is typing in the form when the list checks for an update, their textbox loses focus, often mid-sentence.  Any suggestions as to how I can allow users to work in their part of the page entering data without the AsyncPosbacks messing up their form entry?

    Thanks,

    - Brad

  • Re: Text Box Loses Focus on AsyncPostback

    07-21-2008, 12:00 PM

    Ensure that the UpdatePanel only wraps the list and not the text box as well and I think you should be ok.

  • Re: Text Box Loses Focus on AsyncPostback

    07-22-2008, 12:29 PM
    • Loading...
    • ataxia1
    • Joined on 05-01-2007, 3:16 PM
    • Posts 107

    Dropped the DataGrid and FormView into separate updatepanels, and the same still occurs.  (Only trigger ties the formview Insert button to the DataGrid panel.)

    Any more ideas?

    Thanks,

    - Brad

  • Re: Text Box Loses Focus on AsyncPostback

    07-22-2008, 12:49 PM
    • Loading...
    • JZoerman
    • Joined on 08-24-2006, 6:27 AM
    • FL, U.S.
    • Posts 146

    I came across this scenario myself and never did find a solution using the timer control. However, I did solve the problem using javascript to perform the update.

    JZ

  • Re: Text Box Loses Focus on AsyncPostback

    07-23-2008, 1:51 PM
    • Loading...
    • ataxia1
    • Joined on 05-01-2007, 3:16 PM
    • Posts 107

    Good to know I'm not alone in this.  I have bigger fish to fry at the moment, but if I get time, I may go ahead and write a manual update in JavaScript.

     

    Thanks

  • Re: Text Box Loses Focus on AsyncPostback

    07-24-2008, 12:24 AM
    Answer

    Hi,

    You can put TextBox into another updatepanel and have both of these updatepanels UpdateMode="Conditional".

    Please check this thread: http://forums.asp.net/t/1099345.aspx

    Sincerely,
    Vince Xu
    Microsoft Online Community Support
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question.
  • Re: Text Box Loses Focus on AsyncPostback

    07-24-2008, 9:10 PM
    • Loading...
    • JZoerman
    • Joined on 08-24-2006, 6:27 AM
    • FL, U.S.
    • Posts 146

    Well there is your answer from Vince Xu, no idea how I missed that one.

  • Re: Text Box Loses Focus on AsyncPostback

    07-25-2008, 12:03 AM
    Answer
    • Loading...
    • CallMeLaNN
    • Joined on 06-05-2008, 2:37 AM
    • Posts 42

    You should disable the timer when textbox focus and enable back after textbox blur

    This post will help you

    http://mattberseth.com/blog/2008/05/bug_bash_enablingdisabling_the.html 

    Best regards,
    LaNN
  • Re: Text Box Loses Focus on AsyncPostback

    08-04-2008, 11:49 AM
    • Loading...
    • ataxia1
    • Joined on 05-01-2007, 3:16 PM
    • Posts 107

    That is a great idea--it never even crossed my mind.  I can't thank you enough!

    I couldn't get the version in the link to work, but I did another (simpler) approach, and it works like a charm.

    I dropped the following into my Page_Load event:

    strJavaScript = "//Start and stop the timer so the text boxes don't lose focus" & vbCrLf & _
    "function startTimer() {" & _
    " var timer = $find(""" & Timer1.ClientID & """);" & _
    " timer._startTimer();" & _
    "}" & _
    "function stopTimer() {" & _
    " var timer = $find(""" & Timer1.ClientID & """);" & _
    "timer._stopTimer();" & _
    "}</script>"

    ClientScript.RegisterStartupScript(Me.GetType, "TimerScript", strJavaScript)

    TextBox.Attributes.Add("onFocus", "stopTimer()")
    TextBox.Attributes.Add(
    "onBlur", "startTimer()")

     

  • Re: Text Box Loses Focus on AsyncPostback

    08-07-2008, 9:57 AM
    • Loading...
    • CallMeLaNN
    • Joined on 06-05-2008, 2:37 AM
    • Posts 42

    Haha at last, you mark me as answered. I know the solution about this issue from Matt post is the best one.
    This is the best Idea, no matter how you fix it.

    You and matt using different method but same idea.

    Thanks to Matt.

    Best regards,
    LaNN
Page 1 of 1 (10 items)
Microsoft Communities
Page view counter