Prevent ModalPopupExtender from hiding when ok or cancel is clicked
I am using asp.net ModalPopupExtender on a page and would like to prevent the dialog from hiding when the user clicks the ok button under certain conditions. But I cannot find a way.
I am looking for something like this
ajax: ModalPopupExtender ... OnOkScript = "return confirm (" Are you sure? ")" ...
if the confirmation is incorrect, the modal dialog does not disappear.
0
slolife
source
to share
2 answers
From my understanding, in your specific situation, you don't hook up the button and just hook up the script to handle the conditional code, then you can close it via JS.
+1
Mitchel Sellers
source
to share
The following JavaScript function will allow you to achieve this:
function conditionalHide(clientID)
{
if (confirm('You sure?'))
{
$find(clientID).hide();
}
}
You can hook this up to your asp: Button control in Page_Load
your page event
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
btnOK.OnClientClick = string.Format("conditionalHide('{0}'); return false;",
panPopup_ModalPopupExtender.ClientID);
}
}
Some notes:
-
panPopup_ModalPopupExtender
- your ModalPopupExtender -
return false;
prevents postback from occurring when the user presses the button - You can hardcode
ClientID
the ModalPopupExtender module, but that introduces (additional) maintenance headaches. The above approach is the best one that I have found alleviates this overhead.
+1
Richard Everett
source
to share