protected override void OnInit(EventArgs e) { base.OnInit(e); if (InvalidInputIndicator != null) { InvalidInputIndicator.AttachValidator(this); } // This are special attributes used during the validation. Basically we want to "attach" this validator // to the input control so that we are "aware of" other validators. // // "validatorscounter" = number of validator controls attached to a specific input // "calledvalidatorcounter" = number of validator controls which have been called during the validation. // // During the validation, "calledvalidatorcounter" will change. We can use that to determine // if we are the first validator called by the browser to evaluate the input. // If so, we can safely hide any error indicator that's shown previously if the current input is valid. // // Increment "validatorscounter" value to include this validator int counter = 0; if (InputControl.Attributes["validatorscounter"] != null) { counter = Int32.Parse(InputControl.Attributes["validatorscounter"]); } InputControl.Attributes.Add("validatorscounter", String.Format("{0}", counter + 1)); // set calledvalidatorcounter=0 if (InputControl.Attributes["calledvalidatorcounter"] == null) { InputControl.Attributes.Add("calledvalidatorcounter", "0"); } }
protected override bool EvaluateIsValid() { if (Enabled || ValidateWhenDisabled) { if (ConditionalCheckBox != null) { bool skip = false; if (ConditionalCheckBox is RadioButton) { bool isChecked = (ConditionalCheckBox as RadioButton).Checked; skip = (ValidateWhenUnchecked && isChecked) || (!ValidateWhenUnchecked && !isChecked); } else if (ConditionalCheckBox is CheckBox) { bool isChecked = (ConditionalCheckBox as CheckBox).Checked; skip = (ValidateWhenUnchecked && isChecked) || (!ValidateWhenUnchecked && !isChecked); } if (skip) { return(true); } } string value = GetControlValidationValue(ControlToValidate); if (String.IsNullOrEmpty(value) && IgnoreEmptyValue) { return(true); } if (OnServerSideEvaluate()) { if (InvalidInputIndicator != null) { InvalidInputIndicator.Hide(); } return(true); } if (string.IsNullOrEmpty(InvalidInputCSS)) { if (InputControl.BackColor == InputNormalColor) { InputControl.BackColor = InvalidInputColor; } if (InputControl.BorderColor == InputNormalBorderColor) { InputControl.BorderColor = InvalidInputBorderColor; } } else { if (!InputControl.Attributes["class"].Equals(InvalidInputCSS)) { InputControl.Attributes["class"] = InvalidInputCSS; } } if (InvalidInputIndicator != null) { if (String.IsNullOrEmpty(ErrorMessage)) { InvalidInputIndicator.TooltipLabel.Text = Text; } else { InvalidInputIndicator.TooltipLabel.Text = ErrorMessage; } InvalidInputIndicator.Show(); } string errorMessage = "No error message provided. Stack Trace -\r\n" + Environment.StackTrace; if (!String.IsNullOrEmpty(ErrorMessage)) { errorMessage = ErrorMessage; } else if (!string.IsNullOrEmpty(Text)) { errorMessage = Text; } Platform.Log(LogLevel.Warn, "Control {0} failed server side validation. Error Message: {1}", ControlToValidate, errorMessage); return(false); } return(true); }