private static bool FieldNotAllowNull2(Control control) { if (control is TextBoxPassword) { if (control.Name.ToLower().Contains("txtrepassword")) { TextBoxPassword objPassword = control.FindForm().Controls.Find("txtPassword", true).FirstOrDefault() as TextBoxPassword; TextBoxPassword objRPassword = (TextBoxPassword)control; if (!objPassword.Text.Equals(objRPassword.Text)) { objRPassword.Text = "password not match"; objPassword.ForeColor = Color.Red; objRPassword.ForeColor = Color.Red; isvalid = false; } else { objPassword.ForeColor = Color.Black; objRPassword.ForeColor = Color.Black; } } } else if (control is TextboxPhone) { var txtTextboxPhone = (TextboxPhone)control; if (!IsPhoneNumber(txtTextboxPhone.Text)) { txtTextboxPhone.Text = Validation.PhoneNotFormat; txtTextboxPhone.ForeColor = Color.Red; } else { txtTextboxPhone.ForeColor = Color.Black; } } else if (control is TextBoxValidation) { TextBoxValidation txtBoxValidation = (TextBoxValidation)control; if (txtBoxValidation.AllowNull == false) { if (string.IsNullOrWhiteSpace(txtBoxValidation.Text) && txtBoxValidation.ForeColor != Color.Black) { txtBoxValidation.Text = "null"; txtBoxValidation.ForeColor = Color.Red; isvalid = false; } else { txtBoxValidation.ForeColor = Color.Black; } } } else if (control is TextboxEmail) { TextboxEmail obj = (TextboxEmail)control; if (obj.Text.Length > 0) { if (UtilityFunction.IsValidEmailAddress(obj.Text)) { obj.ForeColor = Color.Black; } else { obj.ForeColor = Color.Red; isvalid = false; } } } if (control.HasChildren) { foreach (Control child in control.Controls) { FieldNotAllowNull2(child); } } return(isvalid); }