How do I prevent the closing of modal popup window(ModalPopupExtender) on postback?

前端 未结 7 506
一向
一向 2020-12-15 22:26

I\'m using Microsoft AjaxControlToolkit for modal popup window.

And on a modal popup window, when a postback occurred, the window was closing. How do I prevent from

7条回答
  •  借酒劲吻你
    2020-12-15 23:30

    Was having this same problem keeping a modal open during postbacks.

    My solution:

    Use EventTarget to determine if the postback is coming from a control in the modal and keep the model open if it is. The postback can come from a control in the modal iff the modal is open.

    In the load event for the page control containing the modal. Determine if the postback is from a child of mine. Determine if it is from the control that is in the modal panel.

        Protected Sub Control_Load(sende As Object, e As EventArgs) Handles Me.Load
            If IsPostBack Then
                Dim eventTarget As String = Page.Request.Params.Get("__EventTarget")
                Dim eventArgs As String = Page.Request.Params.Get("__EventArgument")
    
                If Not String.IsNullOrEmpty(eventTarget) AndAlso eventTarget.StartsWith(Me.UniqueID) Then
                    If eventTarget.Contains("$" + _credentialBuilder.ID + "$") Then
                        ' Postback from credential builder modal.  Keep it open.
                        showCredentialBuilder = True
                    End If
                End If
            End If
        End Sub
    

    In prerender check my flag and manually show the modal

        Protected Sub Control_PreRender(ByVal sende As Object, ByVal e As EventArgs) Handles Me.PreRender
            If showCredentialBuilder Then
                _mpeCredentialEditor.Show()
            End If
        End Sub
    

提交回复
热议问题