简体   繁体   English

在asp.net中的确认消息?

[英]Confirmation message in asp.net?

<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>

and my code behind code is 我的代码背后的代码是

protected void btnSave_Click(object sender, EventArgs e)
{
   string confirmValue = null;
   confirmValue = Request.Form["confirm_value"];
   if (confirmValue == "No")
   {
      some code....
   }
   else
   {
     return;
   }
}

What actually gonig is confirmValue storing the values like yes,No,Yes,No . 实际的gonig是confirmValue,它存储像yes,No,Yes,No类的值。
But for first time it will show confirmation message, I will click on Ok button and some entries will done then I click on save button it will show again message box at this time I will click on Cancel button then it will go into the if condition but confirmvalue is storing First clicked yes and Next time clicked no so it is going into else condition .... 但是第一次它将显示确认消息,我将单击“ Ok按钮,并且将完成一些输入,然后单击“保存”按钮,此时它将再次显示消息框,我将单击“ Cancel按钮,然后它将进入if条件但confirmvalue正在存储第一次单击是,下次单击否,因此它将进入其他条件...。

what i have to do please help me b 我必须做的事请帮助我b

The cleanest way is to simply use the "OnClientClick" property of the button control like so: 最干净的方法是简单地使用按钮控件的“ OnClientClick”属性,如下所示:

OnClientClick="return confirm('Do you want to save data?');"

If the user clicks "No" then the button event will never fire... You don't need any of that other stuff. 如果用户单击“否”,则按钮事件将永远不会触发...您不需要其他任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM