如何在删除记录前显示确认消息框?按钮应仅为YES
或NO
。不是OK
或CANCEL
。我有这个代码,但它只适用于c#winforms ...
if (MessageBox.Show("Delete record no. " + numID.Text + "?", "Confirm User Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
//codes to delete records
}
答案 0 :(得分:1)
如果您正在显示此客户端,那么您应该使用Javascript。一个好方法是使用jQuery dialog方法。例如:
标记:
<div id="dialog-confirm">This is the content</div>
使用Javascript:
$( "#dialog-confirm" ).dialog({
resizable: false,
height:280,
modal: true,
buttons: {
"Yes": function() {
$( this ).dialog( "close" );
},
"No": function() {
$( this ).dialog( "close" );
}
}
});
答案 1 :(得分:1)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type = "text/javascript">
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Do you want to save data?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="btnConfirm" runat="server" OnClick = "OnConfirm" Text = "Raise Confirm" OnClientClick = "Confirm()"/>
</form>
</body>
</html>
检查此链接: