C# 是或否消息框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19968947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
YES OR NO MessageBox
提问by user2971155
How to I display a confirm message box before deleting records? Buttons should be YES
or NO
only. Not OK
or CANCEL
. I have this code but it only works for c# winforms...
如何在删除记录前显示确认消息框?按钮应该是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
}
回答by John Koerner
If you are displaying this client side, then you should use Javascript. A good way to do this is to use the jQuery dialogmethod. For example:
如果您要显示此客户端,则应使用 Javascript。这样做的一个好方法是使用 jQuery对话框方法。例如:
Markup:
标记:
<div id="dialog-confirm">This is the content</div>
Javascript:
Javascript:
$( "#dialog-confirm" ).dialog({
resizable: false,
height:280,
modal: true,
buttons: {
"Yes": function() {
$( this ).dialog( "close" );
},
"No": function() {
$( this ).dialog( "close" );
}
}
});
Fiddle: http://jsfiddle.net/ghLpV/
回答by Monika
<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>
Check this link:
检查此链接: