Determine which UpdatePanel causes the partial (asynchronous) PostBack?

前端 未结 6 1286
花落未央
花落未央 2020-12-05 19:55

In a page contains two UpdatePanels, How can I know which UpdatePanel causes the partial PostBack ?

I mean in the Page_L

6条回答
  •  -上瘾入骨i
    2020-12-05 20:48

    is possible to determine the object inside an update panel an execute the code needed

    If (ScriptManager.GetCurrent(Page).IsInAsyncPostBack) Then
                    Dim id As String = ScriptManager.GetCurrent(Page).AsyncPostBackSourceElementID
                    Dim Obj = UpdatePanel1.FindControlRecursive(id)
                    If Not IsNothing(Obj) Then
                        a = 1
                    End If
    End If
    

    below the function used to find de object inside the update panel. Is an extension of System.Web.UI.Control

    a=1 Is the desired code.

     Public Module thisExtensions
             _
            Public Function FindControlRecursive(control As System.Web.UI.Control, id As String) As System.Web.UI.Control
                If control Is Nothing Then
                    Return Nothing
                End If
                'try to find the control at the current level
                Dim ctrl As Control = control.FindControl(id)
    
                If ctrl Is Nothing Then
                    'search the children
                    For Each child As Control In control.Controls
                        ctrl = FindControlRecursive(child, id)
    
                        If ctrl IsNot Nothing Then
                            Exit For
                        End If
                    Next
                End If
                Return ctrl
            End Function
        End Module
    

提交回复
热议问题