How do I prevent my asp:ModalPopupExtender from closing after or during a postback to the server??
Here is my code:
JAVASCRIPT
// Confirm popup Ok button
function OnOk() {
$('#confirmPopup').hide();
ClickSaveButton(); // does a postback
ShowGridPopup();
}
ASP.NET AJAX
<asp:ModalPopupExtender BehaviorID="confirmPopup" ID="confirmPopup" runat="server"
TargetControlID="butConfirm" PopupControlID="ConfirmView" BackgroundCssClass="modalBackground"
OnOkScript="OnOk();" OnCancelScript="OnCancel();"
OkControlID="yesButton" CancelControlID="noButton">
</asp:ModalPopupExtender>
No matter if I call ShowGridPopup() before or after the postback method ClickSaveButton(), the popup still dissapears. How can I prevent this?
EDIT
Here is the code for the ShowGridPopup() and ClickSaveButton()
function ShowGridPopup() {
if (getID() == "Popup1") {
ShowGridPopup1();
} else if (getID() == "Popup2") {
ShowGridPopup2();
}
}
function ClickSaveButton() {
var _id = $('a[id$="butSave"]').attr("ID");
__doPostBack(_id.replace("_", "$"), '');
}
I have found a way to by pass this, here is my solution: You have to create a new
HiddenFieldcontroller from the server-side in ASP that will be used to store the ID of theModalPopupExtenderthat you want to show after postback, it is set to null if there is no popup to be shown.Next, we need to set the ID to the
HiddenFieldbefore we use the save eventNow, in the code behind, all we need to do is check the value of the
HiddenFieldtext field and we can just do a.Show()on the correct popup accordingly.