如何在ASPX页面上弹出确认框

我看到了几个教程/演示,但无法解决我的ASPX页面(C#)的问题。 我想在按钮点击事件中弹出确认消息框,并在检查条件后选择是和否按钮。

点击按钮后,它将检查条件, 如果(a> b) ,如果条件为真,则确认框将被加强,否则跳过并且没有消息将被加强。 之后如果用户在确认消息框上单击是按钮,它将继续进行。

请提供代码,因为我是初学者。


下面是一个非常简单的例子,初学者使用Bootstrap.Simple复制并粘贴下面的代码,它将工作:

代码隐藏(.cs文件):

protected void Page_Load(object sender, EventArgs e)
{
}

protected void btnClick_Click(object sender, EventArgs e)
{
    lblOutput.Text = String.Empty;
    bool showModal = true;

    if(showModal)
        ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#myModal').modal('show');", true);
}

protected void Decision_Command(object sender, CommandEventArgs e)
{
    lblOutput.Text = "User clicked - " + e.CommandArgument;
}

.ASPX:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
</head>
<body>
    <form id="form1" runat="server">
        <asp:Button ID="btnClick" runat="server" Text="OK" OnClick="btnClick_Click" />
        <asp:Label ID="lblOutput" runat="server"></asp:Label>
        <div id="myModal" class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">Would you like to continue?</h4>
                    </div>
                    <div class="modal-body">
                        <h3>Would you like to coninue?</h3>
                        <asp:Button ID="btnYes" runat="server" Text="Yes" OnCommand="Decision_Command" CommandArgument="Yes" />
                        <asp:Button ID="btnNo" runat="server" Text="No" OnCommand="Decision_Command" CommandArgument="No" />
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
</body>
</html>

输出:

使用Bootstrap弹出确认


这应该让你走上正轨。 yesno不能通过confirm()来实现您必须切换到像sweetalert这样的替代方法

var select = document.getElementById('c'),
    btn    = document.getElementById('check');

// Add click event
btn.onclick = function(){

   var value = select.options[select.selectedIndex].value; // I could also use Boolean(value); to convert it to boolean and not use quote for comparsion.
 
   // Checking if condition is true. If yes, then ask for user confirmation.
   if(value == '1'){
     
      console.log('condition is true; asking for confirmation');
     
      var ask = confirm('The condition is true, do you want to continue?');
      // if confirmed;
      if(ask){
         console.log('confirmed');
      // if denied/cancelled
      } else {
         console.log('cancelled');
      }
   }

}
Condition:
<select id="c">
   <option value="1">true</option>
   <option value="0">false</option>
</select>
<button id="check">Check</button>
链接地址: http://www.djcxy.com/p/71545.html

上一篇: How to popup a confirmation box on condition on ASPX page?

下一篇: How to redirect to another page after a delay