Ren33
Ren33

Reputation:

Textbox gets focus but you can't enter anything

I have an ASP.NET gridview that has dataentry textboxes in the footer row. After the user adds a row, I reset focus to the first textbox in the codebehind using something like Textbox1.focus() in the gridview update handler. The problem is that although it looks like the textbox gets focus (the cursor is flashing in the textbox) you can't enter anything until you click on another textbox on the form and then click back. This only seems to happen in IE8. When I tested this in firefox the textbox got focus and I was able to enter new text right way.

Thanks for any help.

Upvotes: 1

Views: 3005

Answers (2)

Dan R
Dan R

Reputation: 88

I had a similar issue, where a textbox in an update panel would not allow the user to interact despite appearing to have focus until it lost focus and got it back. Like the original poster, it only happened in IE8 in non-compatibility mode.

I implemented the following workaround which seems to do the trick:

ScriptManager.GetCurrent(Me.Page).SetFocus(txtAnotherTextBox)
ScriptManager.RegisterStartupScript(Me, Me.GetType, "Focus", _
"setTimeout(function() { document.getElementById('" _
& txtTextBox.ClientID & "').focus(); }, 200);", True)

Basically, I initially focus on a different control, then register a script to focus on the control that I wanted with a 200ms delay.

Upvotes: 0

Ren33
Ren33

Reputation:

Still haven't found a solution but I just noticed that when IE8 is in compatibility mode the textbox functions as expected. This is the third problem I've had that's related to IE8's compatibility mode.

Upvotes: 1

Related Questions