?
Solved

MessageBox.YesNo

Posted on 2003-02-25
4
Medium Priority
?
1,100 Views
Last Modified: 2012-06-27
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?
0
Comment
Question by:Sprocket46
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Expert Comment

by:hiAsh
ID: 8016016
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
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 200 total points
ID: 8016080
Hello

  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")
       else
         MessageBox.Show("You choosed No")  
        End If

Best regards
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 8019766
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
            Do_Delete()
        Else
            Do_Cancel_Delete()

        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
0
 

Author Comment

by:Sprocket46
ID: 8020132
Thank you very much. Works great!
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question