RequiredDoubleRuleAttribute Client Side Validation

Topics: Developer Forum
Mar 19, 2007 at 12:22 PM
Hi Simon,

After upgrading to the latest source, i notice that the client side validation functionality for databound properties in my control with RequiredDoubleRuleAttribute's assigned no longer works. It works at the server side, just not on the client. I am using a simple textbox as the controltovalidate.

Cheers,

Dan
Coordinator
Mar 20, 2007 at 10:05 AM
This discussion has been copied to Work Item 9027. You may wish to continue further discussion there.
Coordinator
Mar 20, 2007 at 10:51 AM
Dan

This was a bug. Should be fixed on the latest checkin.
Mar 20, 2007 at 12:32 PM
Hi Simon,

Thanks for the reply - yes the bug is fixed, sort of - now it works but does not show the custom ErrorMessage property of the attribute, instead it simply shows:

"The member 'propertyname' is required"

Dan
Coordinator
Mar 20, 2007 at 12:50 PM
Dan

Now populating with the errormessage. Changes are checked in.

Keep the feedback coming :)
Mar 23, 2007 at 3:23 PM
Edited Mar 23, 2007 at 3:25 PM
Hi Simon,

I thought your changes had worked, but what happens now is that i get the ErrorMessage text shown to the client from my RangeDoubleValidator for both when the rangedoublevalidator is invalid, and the also associated RequiredDoubleValidator, eg:

Server B.O.:

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

If i enter "asdf" into the textbox bound against that property, i should see:

Age is required.
Age must be a valid number between 0 and 200.

..but what i actually see is:

Age must be a valid number between 0 and 200.
Age must be a valid number between 0 and 200.

...could you please check it out? This problem only occurs when the validation is rendered by client JS - if i do a postback, i get the correct unique messages. Many Thanks, and have a good weekend!

Dan
Coordinator
Mar 27, 2007 at 8:20 AM
This discussion has been copied to Work Item 9170. You may wish to continue further discussion there.
Coordinator
Mar 27, 2007 at 9:14 AM
Edited Mar 27, 2007 at 9:15 AM
Dan

This is due to the way I was doing the range validations. I was using two CompareValidators, one for the min and one for the max. Unfortunately I was not aware that the CompareValidators perform a type check and you cannot turn off this feature. Hence when you put in letters both validators showed the error message. I have now refactored the code to use a single RangeValidator which will also perform the type check. So now if you put in letters you should get the one error message. Download the latest to have a play with this.


Unfortunately I have not met your expected outcome. That is if you put letters into a numeric field the RequiredRule will kick in. This is because the RequiredFieldValidator does not do a type check. I will do some more research / thinking on this and should have a solution in a few days.
Coordinator
Mar 27, 2007 at 1:15 PM
Dan

Just checked in some code that adds a data type check to the web validator generated from a required rule. This should meet your requirement of
If i enter "asdf" into the textbox bound against that property, i should see:
Age is required.
Age must be a valid number between 0 and 200.

Let me know how you go.

Regards
Simon