private void txtFileName_Validating(object sender, CancelEventArgs e)
 {
     this.m_Isvalid = false;
     if (this.Required == false)
     {
         if (string.IsNullOrEmpty(TbField.Text))
         {
             e.Cancel = false;
             if (sender != null)
             {
                 EpMain.SetError(TbField, null);
             }
             return;
         }
     }
     if (string.IsNullOrWhiteSpace(TbField.Text))
     {
         e.Cancel = true;
         //txtFileName.Focus();
         if (sender != null)
         {
             EpMain.SetError(TbField, string.Format(Properties.Resources.ValidationRequired, lblName.Text));
         }
         return;
     }
     if (TbField.Text.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
     {
         e.Cancel = true;
         //txtFileName.Focus();
         if (sender != null)
         {
             EpMain.SetError(TbField, string.Format(Properties.Resources.ValidationFormat, lblName.Text));
         }
         return;
     }
     if (e.Cancel == false)
     {
         if (sender != null)
         {
             EpMain.SetError(TbField, null);
         }
     }
 }
Esempio n. 2
0
        private void txtName_Validating(object sender, CancelEventArgs e)
        {
            this.m_Isvalid = false;
            if (this.Required == false)
            {
                if (string.IsNullOrEmpty(TbField.Text))
                {
                    e.Cancel = false;
                    if (sender != null)
                    {
                        EpMain.SetError(TbField, null);
                    }

                    return;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(TbField.Text))
                {
                    e.Cancel = true;
                    if (sender != null)
                    {
                        EpMain.SetError(TbField, string.Format(Properties.Resources.ValidationRequired, lblName.Text));
                    }

                    return;
                }
            }
            if (string.IsNullOrEmpty(this.RegularExpression) == false)
            {
                Regex rx = new Regex(
                    this.RegularExpression,
                    RegexOptions.Singleline
                    | RegexOptions.CultureInvariant
                    );
                bool IsMatch = rx.IsMatch(TbField.Text);
                if (IsMatch == true)
                {
                    e.Cancel = false;
                    if (sender != null)
                    {
                        EpMain.SetError(TbField, null);
                    }
                    return;
                }
                else
                {
                    e.Cancel = true;
                    if (sender != null)
                    {
                        EpMain.SetError(TbField, string.Format(Properties.Resources.ValidationFormat, lblName.Text));
                    }
                    return;
                }
            }
            else
            {
                e.Cancel = false;
                if (sender != null)
                {
                    EpMain.SetError(TbField, null);
                }

                return;
            }
        }