views:

12

answers:

1

I'm developing a Word 2010 add in using Visual Studio 2010, and C#.

  • I've created a simple form, with two textboxes, and an Ok button.

  • The Ok button's Causes validation property is set to true.

  • Both textboxes CausesValidation property is set to false, and their Validating and Validated properties are set. This is so that they are only validated when the Ok button is clicked, and not when focus is changed.

If the form code is defined within the Word add in, the validating and validated events run as expected - when the Ok button is clicked. I wanted to make the form reusable, so I moved the form into a separate class library. The form largely works as expected but the validating and validated events never run with the above configuration.

Does anybody know why this is the case? Is it a bug?

A: 

It seems that you can get things working if you:

1) Set the AutoValidate property of the base form to Disable.

2) Set the CausesValidation property on the textbox to true.

3) Call the this.ValidateChildren() method in the button click.

zikoziko