H-SC
asked on
Enable/Disable Button Based On Empty TextBoxes
I have a form that has a button on it with 2 textboxes. Here is what I need to happen.
I need for the button to be disabled if both textboxes are empty. If the user clears out one and one still has data then still disabled.
Only enable when both boxes have data
I need for the button to be disabled if both textboxes are empty. If the user clears out one and one still has data then still disabled.
Only enable when both boxes have data
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Opps, is it in .NET ???
My example is in VB6
My example is in VB6
Create a function like this as given below
and put in following events
textBox1_TextChanged
textBox2_TextChanged
Form1_Load
and put in following events
textBox1_TextChanged
textBox2_TextChanged
Form1_Load
private void checkdata()
{
if (textBox1.Text.Trim().Equals("") || textBox2.Text.Trim().Equals(""))
button1.Enabled = false;
else
button1.Enabled = true;
}
Here is one way of doing it
Private Sub TextChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged
If Me.TextBox1.Text.Length = 0 Or Me.TextBox2.Text.Length = 0 Then
Me.Button1.Enabled = False
Else
Me.Button1.Enabled = True
End If
End Sub
Private Sub TextChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged
If Me.TextBox1.Text.Length = 0 Or Me.TextBox2.Text.Length = 0 Then
Me.Button1.Enabled = False
Else
Me.Button1.Enabled = True
End If
End Sub
for vb6 only code will change to as below
don't forget toput in following events
textBox1_TextChanged
textBox2_TextChanged
Form1_Load
don't forget toput in following events
textBox1_TextChanged
textBox2_TextChanged
Form1_Load
private Sub checkdata
if(Len(Trim(textbox1.Text))==0||Len(Trim(textbox2.Text))==0)
button1.Enabled = false;
else
button1.Enabled = true;
Endif
end sub
ASKER
TSmooth,
That worked great!
That worked great!
Open in new window