Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1112
  • Last Modified:


I have a delete button. Upon click of that button, I have a prompt for with a Yes/No option. I have the "Yes" button working, but the "No" still operates using the "Yes" function. How can I make it call or have it's own function?
1 Solution
The code below can be a solution to your query. You can write this in a Javascript function and call the function in the click event of the Delete Button. This code propmts a message box with the Ok and Cancel buttons and on Clicking on OK the code inside the if block will get executed
*******Code Begins here*********

if(confirm("Are you sure you want to delete?"))
//Code here if the option is 'OK'

*******Code ends here**********

I hope this works for you. All the Best
Mohammed NasmanSoftware DeveloperCommented:

  Get the clicked button using DialogResult

here's quick example using VB.Net, not test yet, because no VS.Net now on hand

        Dim Message As String = "Do you want to save before exit?"
        Dim Caption As String = "Warning"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, _
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)

        If Result = DialogResult.Yes Then
          MessageBox.Show("You choosed Yes")
         MessageBox.Show("You choosed No")  
        End If

Best regards
Sounds like you want:

    Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
        If MsgBox("Do you want to delete?", MsgBoxStyle.YesNo, "Confirm") = MsgBoxResult.Yes Then

        End If
    End Sub

    Private Sub Do_Delete()
        'do stuff to delete something

    End Sub
    Private Sub Do_Cancel_Delete()
        'do stuff to not delete something

    End Sub
Sprocket46Author Commented:
Thank you very much. Works great!

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now