Hi everyone,
In an asp.net project I am currently working on, I need to create a modal popup that will act like the confirm()
javascript function.
However, the native confirm()
function doesn't help out, since a custom design is required.
An earlier attempt for this using the SimpleModal jQuery plugin I split the confirmation and the actual action to 2 different LinkButtons, one of which was hidden.
Clicking the "OK" button on the dialog would trigger the click
event on the hidden LinkButton.
But this feels somewhat like an ugly hack.
Example
This was my early attempt:
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(function() {
$('.confirmation').click(function(e) {
e.preventDefault();
// Find the action button.
var button = $(this).next('.confirmation-action');
confirmation($('.confirmation-popup'), function() {
button.click();
});
});
});
function confirmation(element, callback) {
$.modal(element, {
// ...
onShow: function(dialog) {
// Bind both Yes and No buttons.
dialog.data.find('.no').click(function() {
$.modal.close();
});
dialog.data.find('.yes').click(function() {
$.modal.close();
if ($.isFunction(callback)) {
// Applies the callback, which in turn clicks the action LinkButton.
callback.apply();
}
});
}
});
}
Can anyone some provide different insight on this? Are there any other methods of doing this?
Is it even possible for a modal popup to return a value, like confirm()
does?
Thanks!