Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.




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

1 solution

Change your confirm function like this:

JavaScript
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
VB
<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" />



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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900