C# .NET - how to give condition when textbox is empty if we click the button it shows error

Asked By sarani raji on 15-Jul-13 06:24 AM

This is the code am created and executed but one problem if the user did not give anything in textbox that time also it will show you are successfully registered how to give if text box is empty  the button  shows pls type text box





if ((textBox1.Text == "") && (textBox2.Text == "") && (textBox3.Text == "") && (textBox4.Text == ""))
        {

          MessageBox.Show("You are successfully registered", "success", MessageBoxButtons.OK, MessageBoxIcon.Information);
          this.Hide();
          Form2 frm2 = new Form2();
          frm2.Show();
        }
        else
        if((textBox1.Text.Trim()==string.Empty) && (textBox2.Text.Trim()==string.Empty)&&(textBox3.Text.Trim()==string.Empty)&&(textBox4.Text.Trim()==string.Empty))
        {
          MessageBox.Show("You are not successfully registered", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
          this.Show();
          
        }

Robbe Morris replied to sarani raji on 15-Jul-13 08:51 AM
You are checking for empty textboxes and showing successfully registered in both IF conditions.  Why?

I believe you meant for the first set to be

if(textBox1.Text.Trim() != string.empty && textBox2.Text.Trim() != string.empty and so on...
sarani raji replied to Robbe Morris on 16-Jul-13 02:14 AM
Thank you so much it successfully executed