Example : Empty/Blank box code Validation in C#.
 
                
                if (TxtUserId.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter User Name/Id.",
                                    "Validation",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);

                    TxtUserId.Focus();
                    return;
                }

                
                if (TxtPass.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter Password.",
                                    "Validation",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);

                    TxtPass.Focus();
                    return;
                }


                
                if (TxtCPass.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter Confirm Password.",
                                    "Validation",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);

                    TxtCPass.Focus();
                    return;
                }


                
                if (TxtPass.Text != TxtCPass.Text)
                {
                    MessageBox.Show("Password and Confirm Password do not match.",
                                    "Validation",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);

                    TxtCPass.Focus();
                    return;
                }


                
                if (TxtMob.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter Mobile Number.");
                    TxtMob.Focus();
                    return;
                }


                
                if (RdbMale.Checked == false &&
                    RdbFemale.Checked == false &&
                    RdbOther.Checked == false)
                {
                    MessageBox.Show("Please select Gender.");
                    return;
                }


                
                if (CmbNationality.SelectedIndex == -1 || CmbNationality.Text == "Select One")
                {
                    MessageBox.Show("Please select Nationality.");
                    CmbNationality.Focus();
                    return;
                }


                
                string gender = "";

                if (RdbMale.Checked == true)
                {
                    gender = "Male";
                }
                else if (RdbFemale.Checked == true)
                {
                    gender = "Female";
                }
                else if (RdbOther.Checked == true)
                {
                    gender = "Other";
                }
           

Loading

Categories: Undefined

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.