san

san

  • NA
  • 19
  • 0

Validation - Implicit Explicit Question

Jan 7 2008 4:22 PM
Hey Guys,

I want to Validate forms at a Submit Button Event . Right now I`m using Validating and Validated [Implicit] which validates the form when  the focus changes. This is painful. What I`m looking for is the whole form getting validated at a Button Click event. I can get this to work but this requires some amount of coding, I have a lot of controls so I`ll have to write code for each of them..[or do I?]

When I`m using Implicit Validation I do -
public void Tx_Validating(object sender, CancelEventArgs e)
        {
            Control Ctrl = (Control)sender;


                if (Ctrl.Text.Length == 0)
                {
                    errorProvider1.SetError(Ctrl, " Require Field ");
                }
                else
                {
                    errorProvider1.SetError(Ctrl, "");
                }

        }


        private void SubmitButton_Click(object sender, EventArgs e)
        {

            bool invalidIP = false;
            foreach (Control ctrl in groupBox1.Controls)
            {
                if (errorProvider1.GetError(ctrl).Length != 0)
                {
                    invalidIP = true;
                    break;
                }
            }

            if (invalidIP)
            {
                MessageBox.Show("You still have invalid", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                this.Close();
            }
        }

Can this code be modified for an Explicit Validation.
Any information on getting not to use change of focus event and  implicit validation will be greatly helpful.

Thank You
San