validated if textbox is empty and not empty ,and what is the proper if else statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rexchie
    New Member
    • Nov 2014
    • 2

    validated if textbox is empty and not empty ,and what is the proper if else statement

    Validated if textbox is empty and not empty ,and what is the proper if else statement:
    Code:
    private void btnSave_Click(object sender, EventArgs e)
    {
      if (txtFName.Text == "")
      {
        labelID.Text = "!";
      }
      if (txtLName.Text == "")
      {
        labelLN.Text = "!";
      }
      if (txtMI.Text == "")
      {
        labelMN.Text = "!";
      }
      if (cmbGender.Text == "")
      {
        labelGender.Text = "!";
      }
      if (cmbCollege.Text == "")
      {
        labelCollege.Text = "!";
      }
      if (txtFName.Text == "" || txtLName.Text == "" || txtMI.Text=="" || cmbGender.Text=="" || cmbCollege.Text=="")
      {
                    
        MessageBox.Show("Fill up the remaining field/s");
      }
    Last edited by Frinavale; Nov 24 '14, 09:07 PM. Reason: Added the description posted in the title into the body of the thread so that the code had context. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    What's wrong?
    Your code looks fine to me...?

    You could use the String.IsNullOr Empty Method or the String.IsNullOr WhiteSpace Method to check if strings contain information...

    Comment

    Working...