0

Hi, im trying to disable a button until anything has been entered into two text boxes simultaneously.

So far i have tried:

If String.IsNullOrEmpty(TextBox1.Text & TextBox2.Text) Then
        Button1.Enabled = False
        Else
        Button1.Enabled = True
        End If

However it doesnt work simultaneously, the button will become enabled if i enter anything into either textbox, i cant have any of them left blank.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by SiahCheePing
0

In your code TextBox1.Text & TextBox2.Text concatenates two strings. The resulting string will never be null or empty if either one of the textboxes is not null or not empty.

If String.IsNullOrEmpty(TextBox1.Text) OrElse String.IsNullOrEmpty(TextBox2.Text) Then
      Button1.Enabled = False
    Else
      Button1.Enabled = True
    End If

You have to check those textboxes separately.

0

In your code TextBox1.Text & TextBox2.Text concatenates two strings. The resulting string will never be null or empty if either one of the textboxes is not null or not empty.

If String.IsNullOrEmpty(TextBox1.Text) OrElse String.IsNullOrEmpty(TextBox2.Text) Then
      Button1.Enabled = False
    Else
      Button1.Enabled = True
    End If

You have to check those textboxes separately.

If I'm right, 2 criteria is to be fulfilled.I think it could be modified by changing a little something

If String.IsNullOrEmpty(TextBox1.Text) AndAlso String.IsNullOrEmpty(TextBox2.Text) Then
      Button1.Enabled = False
Else
      Button1.Enabled = True
End If

the orelse changed to AndAlso

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.