In this article I am discussing the problem, ASP.Net AJAX ModalPopupExtender Modal Popup closes when some control within its associated Panel does PostBack, thus here I am providing solution how we can prevent ASP.Net AJAX ModalPopupExtender Modal Popup from closing when some control with its associated Panel performs PostBack.
HTML Markup
The HTML markup consists of an ASP.Net AJAX ModalPopupExtender control, and within its associated Panel an ASP.Net DropDownList, that is doing PostBack on its OnSelectedIndexChanged event.
<cc1:ToolkitScriptManager runat="server">
</cc1:ToolkitScriptManager>
<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>
<!-- ModalPopupExtender -->
Solution
The Solution to this problem is to simply re-open the ASP.Net AJAX Modal Popup by calling its Show method, when some control does PostBack, after the code written for the task to be done, i.e. in the last line simply call Modal Popup 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
That’s all you need to do to re-open thus prevent the ASP.Net AJAX ModalPopupExtender Modal Pop from closing when some control within its associated Panel does PostBack.
Demo
Downloads