In this article I will explain with an example, how to solve ASP.Net AJAX ModalPopupExtender Modal Popup Closes on PostBack.
HTML Markup
The HTML Markup consists of following controls
ScriptManager - For enabling ASP.Net
AJAX.
Button – For triggering the Modal popup to open.
ModalPopupExtender – For displaying Modal popup.
The ModalPopupExtender has been assigned with following properties.
PopupControlID – The control which will be displayed as Modal popup.
TargetControlID – The control which opens the Modal popup.
CancelControlID – The control which closes the Modal popup.
Panel – For displaying content of the Modal popup.
DropDownList – For capturing user input.
The DropDownList has been assigned with an OnSelectedIndexChanged event handler.
Button – For closing the Modal popup dialog box.
<asp:ScriptManager runat="server">
</asp:ScriptManager>
<asp:Button ID="btnShow" runat="server" Text="Show Modal Popup" />
<!-- ModalPopupExtender -->
<cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="btnShow"
CancelControlID="btnClose" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" align="center" Style="display: none">
<div style="height: 100px">
Do you like this product?
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="OnSelectedIndexChanged">
<asp:ListItem Text="Please Select" Value="0"></asp:ListItem>
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="2"></asp:ListItem>
</asp:DropDownList>
</div>
<asp:Button ID="btnClose" runat="server" Text="Close" />
</asp:Panel>
Solution
You will need to simply re-open the ASP.Net AJAX Modal Popup by calling its Show method, when some control does PostBack, i.e. after the code written for the task to be done, in the last line simply call Show method as shown below.
C#
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
//Do work
mp1.Show();
}
VB.Net
Protected Sub OnSelectedIndexChanged(sender As Object, e As EventArgs)
'Do work
mp1.Show()
End Sub
Demo
Downloads