RequiredIntValidatorAttribute Ignored by ValidatorGenerator.GenerateValidators

Topics: Developer Forum
Feb 13, 2007 at 8:11 AM
I have a property on a business object with a RequiredIntValidator applied:

ValidationFramework.RequiredIntValidatorAttribute(ErrorMessage = "Age is required")
ValidationFramework.RangeIntValidatorAttribute(0, 200, ErrorMessage = "Age must be a valid number between 0 and 200")
public int Age
{
get
{
return this._Age;
}
set
{
this._Age = value;
}
}

(...i'm a little optimistic with the max age value ;)

When in my control's code I iterate through its data-bound child controls, I call validatorGenerator.AddValidation for any bound fields which have validation attributes - which in testing includes the RequiredIntValidator. Once iteration is complete I call validatorGenerator.GenerateValidators - which works perfectly on other validators, e.g. RequiredString, RangeInt, Regex etc. On the client side only the RequiredIntValidator is NOT rendered to the page, neither does it cause server side error if the value isnt an int.

Is this a known issue? Thanks.
Feb 13, 2007 at 11:18 AM
slight correction...

The validation is correct at the server side (a validation exception occurs), the problem is that the client side validator is not created.

Dan
Coordinator
Feb 15, 2007 at 11:11 AM
Dan
I have checked in a new design for creating WebValidators (http://www.codeplex.com/ValidationFramework/SourceControl/ListDownloadableCommits.aspx). You will need to alter your code a little to get it to work. Have a look at TraditionalForm2.aspx and GridViewUpdating.aspx for examples.
Client side (javascript) should be created for the following
-CompareStringRule
-LengthStringRule
-RangeStringRule
-RangeStructRule{T}
-RegexRule
-RequiredStringRule
-RequiredStructRule{T}
And server side validators should be created for all other rules.
The code is not finalized yet, still needs some more doco and testing, so it may change a little before it is included in the next release.
Hopefully this should fix your problems.

More doco and examples will be included over the next few checkins.

Let me know if you have any problems.