Skip to content

Instantly share code, notes, and snippets.

@tncbbthositg
Created March 13, 2012 19:44
Show Gist options
  • Save tncbbthositg/2031107 to your computer and use it in GitHub Desktop.
Save tncbbthositg/2031107 to your computer and use it in GitHub Desktop.
Confirming action with a popup...
// Usage examples
//
// Calls the default asp.net event for the control
// OnClientClick = "return confirmAction('Are you sure?', this);"
//
// Uses your own function
// OnClientClick = "return confirmAction('Are you sure?', function() { window.alert('No Way!'); });"
//
// Uses built in browser confirmation
// OnClientClick = "return confirmAction('Are you sure?');"
function confirmAction(message, delegate) {
if (typeof (delegate) === "undefined")
return window.confirm(message);
var action;
if (typeof (delegate) === "function")
action = delegate;
else if (typeof (delegate) === "object")
action = function () { __doPostBack(delegate.name, ''); };
$("<div>" + message + "</div>").dialog({
modal: true,
draggable: false,
buttons: {
"OK": function () { $(this).dialog("close"); action(); },
"Cancel": function () { $(this).dialog("close"); }
},
title: "Are you Sure?"
});
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment