首次单击操作后,Javascript Confirm功能不会执行 [英] Javascript Confirm function does not execute after first click action

查看:303
本文介绍了首次单击操作后,Javascript Confirm功能不会执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多次单击按钮后,if子句中的vb代码不会执行。 (不执行后续点击操作)。请帮忙。









The vb code inside the if clause does not execute after the button has been clicked more than once. (Does not execute subsequent click actions). Please help.




<script type = "text/javascript">
         function Confirm() {
             var confirm_value = document.createElement("INPUT");
             confirm_value.type = "hidden";
             confirm_value.name = "confirm_value";
             if (confirm("Confirm to Delete Account")) {
                 confirm_value.value = "Yes";
             } else {
                 confirm_value.value = "No";
             }
             document.forms[0].appendChild(confirm_value);
         }
    </script>


<body>
    <form id="form1" runat="server">   <%-- HTML code --%>
<asp:Button ID="Delete_Account" runat="server" OnClick="Delete_Account_Click"

                          OnClientClick=" Confirm()" Text="Delete Account" Width="250px"

                          BorderColor="Silver" Font-Size="19px" Height="45px" Font-Bold="True"

                     Font-Names="Times New Roman" />
</form>
</body>


VB code
Dim confirmValue As String = Request.Form("confirm_value")
        If confirmValue = "Yes" Then
'actions to perform
end if

推荐答案

更改你的确认功能就像这个:



Change your confirm function like this:

function confirmDelete () {// note that it is custom to name methods with lower case letter
    return confirm("You're about to delete the account. Are you sure?");
}







并改变你的按钮




And change your button to

<asp:Button ID="Delete_Account" runat="server" OnClick="Delete_Account_Click"
                          OnClientClick=" javascript return confirmDelete();" Text="Delete Account" Width="250px"
                          BorderColor="Silver" Font-Size="19px" Height="45px" Font-Bold="True"
                     Font-Names="Times New Roman" />







通过从客户端脚本返回false来防止服务器往返,您的服务器点击处理程序将永远不会触发。




By returning false from client side script you're preventing server round-trip, your server click handler will never trigger.


这篇关于首次单击操作后,Javascript Confirm功能不会执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆