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
2010-09-23 09:17:21
@anishmarokey - i believe the OP is talking about invoking his "validators" only on button click instead of on focus lost
InSane
2010-09-23 09:24:18
I ended up using this
m.edmondson
2010-09-27 08:17:53
+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
2010-09-23 10:42:16