Search code examples
c#asp.netjavascriptonclientclick

Delete Button issue


I am using one link button in an asp.net application for delete purpose. For the confirmation i added the property of OnClientclick="return ValidateOnDelete();". By Default it works as fine. But i have One condition is that When the user is not admin, the delete button will be disabled. My problem is that, if the user clicks on the delete button when it is in disabled mode, the confirmation message will come. How it can avoid this issue?


Solution

  • pass the button to the ValidateOnDelete() function using

    OnClientclick="return ValidateOnDelete(this);"
    

    then within the ValidateOnDelete() function do a test for the button disabled status

    function ValidateOnDelete(button) {
       if (button.disabled) return false;
    }