0
我在UpdatePanel中有四個文本框,並且AutoPostBack設置爲全部爲True。當用戶輸入一個值並點擊Enter時,我希望光標自動移動到下一個文本框。當我沒有UpdatePanel中的控件時,標準的textbox.focus方法可以正常工作。將焦點設置到UpdatePanel中的文本框
我發現了一些代碼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在任何領域我先試。之後,該事件被解僱,但重點不會改變。有什麼額外的我需要爲以後的電話?
我將不勝感激任何建議。謝謝!