0
string input = Microsoft.VisualBasic.Interaction.InputBox("To change your email, enter it below. The current email on file is " + ParseUser.CurrentUser.Email, "Change Email", "New Email", -1, -1);

Given the above code, how can I check if the cancel button or OK button is pressed? If the user presses OK, I want to run a method. If they press cancel, then I wouldn't run the method.

Checking if the string is 0 characters long won't do because even if the user starts typing and presses cancel, I still don't want the method to run.

Dom
  • 1
  • 3
  • Doesn't it return an empty string when they hit cancel? Why does checking for an empty string not work? – David Sherret Apr 20 '15 at 17:49
  • Does this answer your question? [How to distinguish InputBox Cancel from OK button?](https://stackoverflow.com/questions/19679489/how-to-distinguish-inputbox-cancel-from-ok-button) – StayOnTarget Jul 22 '21 at 21:03

2 Answers2

0

If checking for 0 characters is insufficient to tell whether or not Cancel was clicked, then you'll need to build your own dialog to use in place of the InputBox.

Russ
  • 4,091
  • 21
  • 32
  • Ok would you mind telling me how to do that please? I'm new to C# – Dom Apr 20 '15 at 17:43
  • This is true, it's in the MSDN article for that method: https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.interaction.inputbox(v=vs.110).aspx – Kioshiki Apr 20 '15 at 17:44
  • @Dom: That is pretty fundamental to C#. Perhaps your time would be wisely spent on a tutorial: https://msdn.microsoft.com/en-us/library/aa288436%28v=vs.71%29.aspx – Russ Apr 20 '15 at 17:45
0
var answer = confirm('Are You Sure');
if (answer) {
   //...
} else {
   //...
}


//answer will be true here`enter code here`
Taran
  • 2,895
  • 25
  • 22