4

如何在删除记录之前显示确认消息框?按钮应该是YESNO只有。不是OKCANCEL。我有这个代码,但它只适用于 c# winforms...

if (MessageBox.Show("Delete record no. " + numID.Text + "?", "Confirm User Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
    //codes to delete records
}
4

2 回答 2

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>

检查此链接:

http://aspsnippets.com/Articles/Server-Side-Code-Behind-Yes-No-Confirmation-Message-Box-in-ASPNet.aspx

于 2013-11-14T05:02:08.707 回答
1

如果要显示此客户端,则应使用 Javascript。一个很好的方法是使用 jQuery对话框方法。例如:

标记:

<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" );
        }
      }
 });

小提琴:http: //jsfiddle.net/ghLpV/

于 2013-11-14T03:40:27.883 回答