我在UpdatePanel中有四个文本框,并且所有这些文件框的AutoPostBack都设置为True。当用户输入一个值并按Enter键时,我希望光标自动移动到下一个文本框。当我在UpdatePanel中没有控件时,标准的textbox.focus方法可以正常工作。
我找到了一些代码here,这导致我创建了这个:
Protected Sub txtField_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtField1.TextChanged,
txtField2.TextChanged, txtField3.TextChanged
'Based on the textbox where data was changed, move the cursor to the next field.
Try
Dim sm As ScriptManager = ScriptManager.GetCurrent(Me)
'As multiple textboxes fire this same event, determine which textbox triggered this.
Dim MyTextbox As TextBox = TryCast(sender, TextBox)
Select Case MyTextbox.ID.ToString
Case "txtField1"
sm.SetFocus(txtField2)
Case "txtField2"
sm.SetFocus(txtField3)
Case "txtField3"
sm.SetFocus(txtField4)
End Select
Catch ex As Exception
lblError.Text = "Error in [txtField_TextChanged]: " & ex.Message
End Try
End Sub
真正奇怪的是,这在我首先尝试的任何领域都有效 ONCE 。之后,事件被触发,但焦点不会改变。我需要为后续电话做些什么吗?
我将不胜感激任何建议。谢谢!
答案 0 :(得分:0)
尝试将EnablePartialRendering
的{{1}}属性设置为ScriptManager
,如下所示:
false
我希望这有帮助!祝你好运,编码愉快:)。