Friday, 16 November 2012

A code i wrote to check if multiple text boxes are empty using c#

 it will check a list of check box and show an error at each point. just create the object required in you application and consume the class by creating an object of it and passing value into the method of the class.
class Validationsclass
    {
        public bool CheckTextBooxes(List<TextBox> textboxlist, ErrorProvider ErrorChecker)
        {
            bool flag;
            int i = 0;
            foreach (TextBox txtbox in textboxlist.Where(e=>e.TextLength==0))
            //foreach(var control in controls.Where(e => String.IsNullOrEmpty(e.Text)
            {
                    i += 1;
                    ErrorChecker.Icon = Properties.Resources.Alert_36;
                    ErrorChecker.SetError(txtbox, "pls fill the required fields");
            }
            if (i > 0)
            {
                flag = true;
            }
            else
            {
                flag = false;
            }
            return flag;

        }
    }

No comments:

Post a Comment