I have two text box. If 1 of the textbox.text is empty, the MessageBox would show to prompt user that they did not enter the fields completely. However it does not work…
This is the code:
private void tab1nextButton_Click(object sender, RoutedEventArgs e)
{
if ((AntcbatchpathTextBox.Text == null) || (MasterbuildpropertiespathTextBox.Text == null))
{
System.Windows.MessageBox.Show("You have not specified the paths completely!");
}
else
{
Tabitem2.Visibility = Visibility.Visible;
Tabcontrol1.SelectedIndex = 1;
}
}
I tried to add breakpoint to examine the immediate values. When either one of the Textbox.Text is empty, the immediate value is “” respectively. Is there anything wrong with my code?
String.Emptyandnullare not the same.In your case of an empty
TextBoxit will always beString.Empty.You should check for
Emptywith theString.IsNullOrEmptymethod:or
See also this SO question/answers: In C#, should I use string.Empty or String.Empty or “” ?