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
You can call Show()
method during postback to prevent the modal popup window from closing
MyModalPopoupExtender.Show()
Following previous case...
In Simple.aspx, user has to enter the name of a company. If user don't remember name of the company, he can click a button which will open a pop up modal window.
what I want to do in the modal window is permit the user to do a search of a list of companies. He can enter a partial name and click search. Matches will be shown in a list below. He can click in an item of the list and return. If company does not exist, he can click a button 'New' to create a new company.
So, as you can see, I want a lot of functionality in this modal window.
Thanks!
JC
Like you prolly already know, the modal popup is clientside only, yeah you can gather informations in it during the postback, but if you do a postback he will hide 100% of the time.
Of course, like other proposed, you can do a .show during the postback, but it depends on what you need to do.
Actually, I don't know why you need a postback, if it's for some validations try to do them clientside.
Could you tell us why you need to do a postback, maybe we could help you better ! :)
Put you controls inside the update panel. Please see my sample code, pnlControls is control that holds controls that will be displayed on popup:
<asp:Panel ID="pnlControls" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="TestButton" runat="server" Text="Test Button" onclick="TestButton_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
This will do the job for you :)
Best regards, Gregor Primar
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
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
// reshow
MyModalPopup.Show()
}
}