Reputation: 1
private void UserForm_Load(object sender, EventArgs e)
{
if (txtUsername.Text != "" || txtPassword.Text != "" || txtID.Text != "" || txtFirstName.Text != "" || txtMiddleName.Text != "" || txtLastName.Text != "" || txtDep.Text != "")
{
btnNext.Enabled = true;
}
else
{
btnNext.Enabled = false;
}
}
I was trying to make a form where the button is disabled and once the textboxes
filled up with data, the button will be enabled.
The problem is, the button is disabled even the textboxes is already filled with data.
Upvotes: 0
Views: 84
Reputation: 3367
That's because you are not checking if you should enable the button OnChange of the text field each time. You are checking only on UserForm_Load(object sender, EventArgs e)
This is what you need:
private void textBox__TextChanged(object sender, EventArgs e)
{
if (txtUsername.Text != "" || txtPassword.Text != "" || txtID.Text != "" || txtFirstName.Text != "" || txtMiddleName.Text != "" || txtLastName.Text != "" || txtDep.Text != "")
{
btnNext.Enabled = true;
}
else
{
btnNext.Enabled = false;
}
}
Upvotes: 0
Reputation: 62498
That is happening because you might be populating the control later and checking the text boxes first in the code.
The code to enable and disable the controls should be called after the controls get populated with the values. So, you just need to call your code at right time.
Upvotes: 1