0

Windows form application(.Net 3.5) I have a textbox and a button on the form. I want to disable the button once the textbox is empty. I don't want to use this method. Because the button is still enabled.

Thanks.

Community
  • 1
  • 1

4 Answers4

3

In the event handler for TextChanged, simply determine if the text box contains any data. If it does, enable it. Otherwise, disable it. Add your event handler and then implement something like the following,

private void textBox1_TextChanged(object sender, EventArgs e)
{
   button1.Enabled = !(textBox1.Text == String.Empty);
}
George Johnston
  • 31,652
  • 27
  • 127
  • 172
0

Handle the on text change event

check and see what textbox.text is like this

  if(string.IsNullOrEmpty(textbox1.text))
 {
  Button1.enabled = false;
 }
Micah Armantrout
  • 6,781
  • 4
  • 40
  • 66
0

if you want to disable the textbox, then using textChanged:

if (textbox.Text == ""){
   button.Enabled = false;
}

Hope it helps

Ignacio Gómez
  • 1,587
  • 4
  • 23
  • 41
0

Make button1.Enabled = false;

and add EventHandler to textbox1.TextChanged = new System.EventHandler(SearchBoxTextChanged);

private void textbox1_TextChanged(object sender, EventArgs e)
    {
        button1.Enabled = (textBox1.Text.Trim() != string.Empty);
    }