views:

63

answers:

2

When trying to validate controls on a windows form I realise the .validated() for each controls fires when the focus is lost. Instead I'd like to validate only when the button is pressed at the bottom, how would I do this?

A: 

you can check all the validation condition in Button_Click

/// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button1_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(txtUserName.Text))
        {
            MessageBox.Show("Please enter user Name");
        }
        else if(condition)
        {
         }
         ...........
    }
anishmarokey
@anishmarokey - i believe the OP is talking about invoking his "validators" only on button click instead of on focus lost
InSane
I ended up using this
m.edmondson
+1  A: 

Set AutoValidate to AutoValidate.Disable and in button click event call the ValidateChildren() method (it will fire all "validating/validated" events). MSDN

nihi_l_ist