Reputation: 4732
$(document).ready(function () {
$('.abc').click(function () {
var status = $("#<%=ddlstatus.ClientID%>").val;
if (status == "Prepared") {
var _Action = confirm('Do you really want to cancel this payment ? All pending money will be available in the retention account of the contractor ');
if (_Action) {
$.blockUI({ css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .5,
color: '#fff'
}
});
return true;
}
else {
return false;
}
}
});
});
I get the OK button when I run this javascript but I want to add a cancel button as well. Plus i am calling this from c# code behind
Upvotes: 0
Views: 1480
Reputation: 103365
You can try using jQuery UI Dialog:
<div id="dialog" title="Confirmation Required">
Do you really want to cancel this payment? All pending money will be available in the retention account of the contractor.
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#dialog").dialog({
autoOpen: false,
modal: true
});
});
$(".abc").click(function(e) {
e.preventDefault();
var targetUrl = $(this).attr("href");
var status = $("#<%=ddlstatus.ClientID%>").val();
$("#dialog").dialog({
buttons : {
"Ok" : function() {
if (status == "Prepared") {
$.blockUI({ css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .5,
color: '#fff'
}
});
}
window.location.href = targetUrl;
},
"Cancel" : function() {
$(this).dialog("close");
}
}
});
$("#dialog").dialog("open");
});
</script>
DEMO: http://jsfiddle.net/rCVrc/
EDIT:
Quoting Nick's answer here, you can use the ScriptManager.RegisterStartupScript()
method, like this:
ScriptManager.RegisterStartupScript(this, GetType(), "modalscript",
"$(function() { $('#dialog').dialog({
buttons : {
'Ok' : function() {
if (status == 'Prepared') {
$.blockUI({ css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .5,
color: '#fff'
}
});
}
window.location.href = targetUrl;
},
'Cancel' : function() {
$(this).dialog('close');
}
}
}); });", true);
"If you're not using a ScriptManager/UpdatePanels, use the equivalent ClientScriptManager
version.
It's important to remember to wrap your code in a document.ready handler (IE has the most issues without it), so your elements (in my example, id="dialog"
) are in the DOM and ready."
Upvotes: 2
Reputation: 898
confirm()
should do the trick. Check this link. http://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm
Upvotes: 0
Reputation: 4613
This is a long shot, but does using window.confirm()
give any improvement over confirm()
?
Upvotes: 0