使用textchanged回发后维护Tab索引

时间:2018-05-22 19:31:48

标签: asp.net vb.net

我有3个文本框,其中AutoPostBack = true。在回发后,它失去了它的重点。我一直在寻找和尝试很多东西,但没有任何工作。

下面的代码是我尝试做的事情的片段。

基本上这第一个片段并没有抓住任何东西。有谁知道我在这里做错了什么

**旁注我没有使用Update Panel我使用LayoutItemNestedControlContainer

        Dim ctrl = From control In wcICausedPostBack.Parent.Controls.OfType(Of WebControl)()
                   Where control.TabIndex > indx
                   Select control






Protected Sub txtDEPTH_TextChanged(sender As Object, e As EventArgs) Handles txtDEPTH.TextChanged
    UpdateProductTemp()

    txtDEPTH.Focus()
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Page.IsPostBack Then
        Dim wcICausedPostBack As WebControl = CType(GetControlThatCausedPostBack(TryCast(sender, Page)), WebControl)
        Dim indx As Integer = wcICausedPostBack.TabIndex

        Dim ctrl = From control In wcICausedPostBack.Parent.Controls.OfType(Of WebControl)()
                   Where control.TabIndex > indx
                   Select control

        ctrl.DefaultIfEmpty(wcICausedPostBack).First().Focus()

    End If



End Sub

Protected Function GetControlThatCausedPostBack(ByVal page As Page) As Control
    Dim control As WebControl = Nothing
    Dim ctrlname As String = page.Request.Params.[Get]("__EVENTTARGET")

    If ctrlname IsNot Nothing AndAlso ctrlname <> String.Empty Then
        control = page.FindControl(ctrlname)
    Else

        For Each ctl As String In page.Request.Form
            Dim c As Control = page.FindControl(ctl)

            If TypeOf c Is TextBox OrElse TypeOf c Is DropDownList Then
                control = c
                Exit For
            End If
        Next
    End If

    Return control
End Function

0 个答案:

没有答案