Beispiel #1
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 (!string.IsNullOrEmpty(InvalidInputCSS))
                    {
                        InputControl.RemoveCssClass(InvalidInputCSS);
                    }

                    if (InvalidInputIndicator != null)
                    {
                        if (!InvalidInputIndicator.IsVisible)
                        {
                            InvalidInputIndicator.Hide();
                        }
                    }

                    return(true);
                }

                if (string.IsNullOrEmpty(InvalidInputCSS))
                {
                    if (InputControl.BackColor == InputNormalColor)
                    {
                        InputControl.BackColor = InvalidInputColor;
                    }
                    if (InputControl.BorderColor == InputNormalBorderColor)
                    {
                        InputControl.BorderColor = InvalidInputBorderColor;
                    }
                }
                else
                {
                    InputControl.AddCssClass(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);
        }