JavaScript confirm cancel button not stopping JavaScript

You are treating the confirm is if it is a if statement, it just returns a Boolean true or false.

if(confirm('foo')){ alert('bar'); }

onclick="if (confirm('Are you...?')) commentDelete(1); return false"

You are missing an if. In your version, first you get a question, and then regardless of the answer, you call commentDelete.


In the head tag you can write following code:

<script language="javascript" type="text/javascript">

    function getConfirmation()
    {
        var retVal = confirm("Do you want to continue ?");
        if (retVal == true)
        {
            alert("User wants to continue!");
            return true;
        } 
        else
        {
            alert("User does not want to continue!");
            return false;
        }
    }
</script>

After writing this code you can call this function in the following code:

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
    CommandName="Edit" Text="Edit" **OnClientClick="getConfirmation()"**>
</asp:LinkButton>