Reputation: 46222
I like to check if 2 of the textboxes have data in them. If so, I would like to do some processing.
I have the following code but not sure why it executes even when one of the textboxes is empty:
if (!(string.IsNullOrWhiteSpace(txtUp.Text) && (string.IsNullOrWhiteSpace(txtLower.Text))))
{
// Go here only if both textboxes have data in them
}
Upvotes: 0
Views: 46
Reputation: 172398
You may try this ie, you are missing to put both the condition in brackets()
as you want to check both and then !
them:-
if (!((string.IsNullOrWhiteSpace(txtUp.Text) && (string.IsNullOrWhiteSpace(txtLower.Text)))))
Upvotes: 2
Reputation: 3493
You are missing a !
in your seccond condition. Should be:
here
v
if (!string.IsNullOrWhiteSpace(txtUp.Text) && !string.IsNullOrWhiteSpace(txtLower.Text))
{
// Go here only if both textboxes have data in them
}
Also, the parentheses were messed up
Upvotes: 3