Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
119
rated 0 times [  122] [ 3]  / answers: 1 / hits: 23147  / 13 Years ago, fri, may 27, 2011, 12:00:00

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(_, $), '');
}

More From » asp.net

 Answers
11

I have found a way to by pass this, here is my solution: You have to create a new HiddenField controller from the server-side in ASP that will be used to store the ID of the ModalPopupExtender that you want to show after postback, it is set to null if there is no popup to be shown.



<!-- Grid Popup ID: to obtain the grid popup ID from server-side -->
<asp:HiddenField id=gridPopupID runat=server value= />


Next, we need to set the ID to the HiddenField before we use the save event



// Confirm popup Ok button
function OnOk() {
$('#confirmPopup').hide(); // hides the current confirmation popup
$(#<%= gridPopupID.ClientID %>).val(getID()); // set the ID to the hiddenField.
ClickSaveButton(); // simulates the click of the save button
}


Now, in the code behind, all we need to do is check the value of the HiddenField text field and we can just do a .Show() on the correct popup accordingly.



Protected Sub OnSaveAssociation(ByVal sender As Object, ByVal e As EventArgs) Handles butSaveAssociation.Click

' ommited code: save changes to back end

' determine which popup to show
Dim _id As String = gridPopupID.Value
Select Case _id
Case Popup1
gridPopup1.Show()
gridPopupID.Value = Nothing
Case Popup2
gridPopup2.Show()
gridPopupID.Value = Nothing
End Select

End Sub

[#92012] Thursday, May 26, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jessie

Total Points: 713
Total Questions: 87
Total Answers: 109

Location: Australia
Member since Sat, May 27, 2023
1 Year ago
;