Guys, I found a trick to solve the AjaxControlToolkit's ModalPopup Extender automatic close when PostBack.
- Dont use the "TargetControlID" to call the ModalPopup, but "TargetControlID" cannot be empty, you must set it.
- Add a new HiddenField control, e.g: "HiddenField1"
- Set the "TargetControlID" to "HiddenField1"
- but without set "TargetControlID", how to call it?
the easy way is use "Show()" method. e.g:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
ModalPopupExtender1.Show()
End Sub
- "OkControlID" and "CancelControlID" also do not set it.
Use the "Hide" method.
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
ModalPopupExtender1.Hide()
End Sub
You are almost solve the problem, but if you still have problem. You can try this:
- Use the ViewState keep track the Popup Window is display or not
Public Property PopupIsDisplay() As Boolean
Get
Return ViewState("PopupIsDisplay")
End Get
Set(ByVal value As Boolean)
ViewState("PopupIsDisplay") = value
End Set
End Property
- When you click the button to show popup window, update the ViewState
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
ModalPopupExtender1.Show()
PopupIsDisplay=True
End Sub
- When hide the popup window,
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
ModalPopupExtender1.Hide()
PopupIsDisplay=False
End Sub
- Finally, In "Form_Load", double check the popup window is display or not, if not, show again.
If PopupIsDisplay Then
ModalPopupExtender1.Show()
Else
ModalPopupExtender1.Hide()
End If

