[C#] Button not enabled help!

Dean25800

Newbie
Messages
17
Reaction score
1
Button not enabled help!

Can anyone tell me how to make a button non-enabled until the user has typed in 2 textboxes, this works for one...

Code:
Button1.Enabled = (textBox1.Text == "") ? false : true;
I've also tried this but it doesn't work for 2.

Code:
            bool teacher = textBox1.Text == "" && textBox2.Text == "";
{
Button1.Enabled = (teacher) ? false : true;
}
 

abro1313

Newbie
Messages
15
Reaction score
0
Re: Button not enabled help!

try this. idk if this is what u mean

if (textBox1.Text == ("") && textBox2.Text == (""))
MessageBox.Show("type stuff");
else
{
///whatever you want it to do
}
 

thrasher4001

Newbie
Messages
13
Reaction score
0
Re: Button not enabled help!

idk maybe this???
Code:
{
if (string.IsNullOrEmpty(TextBoxX1.Text)) {
ButtonX1.Enabled = false;
}
else {
ButtonX1.Enabled = true;
}
if (string.IsNullOrEmpty(TextBoxX2.Text)) {
ButtonX1.Enabled = false;
}
else {
ButtonX1.Enabled = true;
}
}
 

GoldBl4d3

VIP
VIP
Retired
Messages
3,778
Reaction score
1,434
Re: Button not enabled help!

no, hes trying to use a form of linq in it.

Hence the "? false : true"

Double click textBox1 and put this code in it:

Button1.Enabled = ((textBox1.Text == "") ? false : true);
 

Dean25800

Newbie
Messages
17
Reaction score
1
Re: Button not enabled help!

Goldbl4d3

That works, but i want the button to not be enabled until you have wrote in
e.g. textBox1 and textBox2

*UPDATE*

figured it out
problem was i couldn't be bothered trying -]
 
Top Bottom