【问题标题】:YES OR NO MessageBox [duplicate]是或否消息框[重复]
【发布时间】:2013-11-26 22:47:18
【问题描述】:

如何在删除记录前显示确认消息框?按钮只能是 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
}

【问题讨论】:

  • 您需要添加对 System.Windows.Forms 库的引用,并且您必须在程序中引用它,例如 -> using System.Windows.Forms;声明。
  • 取决于您使用的技术,一个好的建议是使用 Javascript 的确认功能。请将其嵌入到您的代码中,让用户决定,然后继续您的操作。有一个similar question about it hereHere is some more lightAnd a good example in this link。希望对你有帮助,
  • 我收到此错误The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)
  • 您不想使用 Windows.Forms.MessageBox。别傻了。
  • 没有是/否选项

标签: c# asp.net


【解决方案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" );
        }
      }
 });

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

【讨论】:

    【解决方案2】:
    <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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-05
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多