I have a problem when checking if a textBox is empty.
I have read many questions and answers here, and I have used the codes mentioned but with no luck.
I just want to check if a textBox is empty, and if it is then do something, if not, do something else.
So far I have tried the following codes:
(textBox4 != null && !string.IsNullOrEmpty(textBox4.Text))
(textBox4.Text == "")
(!String.IsNullOrEmpty(textBox4.text)
(textBox4.Text != Stirng.Empty)
(textBox4.Text.Trim() == "")
(textbox4.Text.Length == 0)
None of the codes show any errors, but they still do not work.
Here is my complete code for what I am trying to do:
private void textBox4_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
double a = Convert.ToDouble(textBox10.Text);
double c = Convert.ToDouble(textBox2.Text);
double d = Convert.ToDouble(textBox3.Text);
double ee = Convert.ToDouble((0.13 * d) * 2);
if (string.IsNullOrEmpty(textBox4.Text))
{
textBox15.Text = Math.Round((((((ee / 2) / c) * 0.13) + (d * 0.13)), 4).ToString();
}
else
{
textBox15.Text = (((((a / 2) / c) * 0.13) + (d * 0.13)) / b).ToString();
}
}
catch
{
}
}
(textBox 3,10,15 are IsReadOnly="True", and the Keyboard is InputScope="Number", if that matters)
What am I doing wrong? I feel like I have tested every code there is, and I don't understand why it doesn't check if the textBox4 is empty.
EDIT:
When I write something in textBox4, the code works, and when I delete the entry from textBox4 it detects that the textBox4 is empty (but that's late)
EDIT 2:
This same If/Else code for textBox15 is written under the TextChanged events for all of the other textBoxes involved (1,2,3,4,10,15).
When I put a Breakpoint on the If and Else statements, it gets executed only when:
The code works for the If statement only when I type something in textBox4 and then delete it.
It works for Else statement only when I type something, then delete it, and then retype it again.