CustomValidator

P

Paolo Benetti

Dear all,

I'm trying to add a CustomValidator that must validate a TextBox, ensuring
that the number inserted be in a range of long.
I cannot use RangeValidator because long is not a supported type, and in
addition I wanted to learn to develop a Custom Validator control.

Everything worked fine until I tryied to add 2 different LongRangeValidator
controls on the same page, with 2 different ranges. The problem is that my
ClientValidationFunction is built at runtime with the range limits stamped
in it, that results in the following code rendered:

function ClientLongRangeValidation(source, arguments) {
arguments.IsValid = false;
if (!isNaN(arguments.Value)) {
var val = arguments.Value
if (arguments.Value >= -9223372036854775808 && arguments.Value <=
9223372036854775807)
arguments.IsValid = true;
}
}

I see that the normal RangeValidator control adds some interesting rows at
the bottom of the page:
var gnIB1_ctl02 = document.all ? document.all["gnIB1_ctl02"] :
document.getElementById("gnIB1_ctl02");
gnIB1_ctl02.controltovalidate = "gnIB1_gnTxt1";
gnIB1_ctl02.type = "Integer";
gnIB1_ctl02.evaluationfunction = "RangeValidatorEvaluateIsValid";
gnIB1_ctl02.maximumvalue = "2147483647";
gnIB1_ctl02.minimumvalue = "0";

While CustomValidator just adds the following:
var gnIB2_ctl02 = document.all ? document.all["gnIB2_ctl02"] :
document.getElementById("gnIB2_ctl02");
gnIB2_ctl02.controltovalidate = "gnIB2_gnTxt2";
gnIB2_ctl02.errormessage = "Invalid. Min:-9223372036854775808, max:
9223372036854775807";
gnIB2_ctl02.evaluationfunction = "CustomValidatorEvaluateIsValid";
gnIB2_ctl02.clientvalidationfunction = "ClientLongRangeValidation";

It's seems that if I could add a minimumvalue and a maximumvalue fields for
each control, I could write a different client function that would work with
as many controls I'd like.

But how can I add "javascript fields"?
I see that CustomValidator inherits RegisterValidatorCommonScript and
RegisterValidatorDeclaration, but I don't think they're the right methods.

Any help would be appreciated, Thanks.
Paolo Benetti.
 
P

Paolo

Hi Alessandro,

you saved me from insanity.
It works perfectly now.

Many thanks,
Paolo.


Alessandro Zifiglio said:
hi Paolo, you can register you two propertis as expando attributes. The
method you are looking for is RegisterExpandoAttribute.

http://msdn2.microsoft.com/en-us/library/ms153123.aspx

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net


Paolo Benetti said:
Dear all,

I'm trying to add a CustomValidator that must validate a TextBox,
ensuring
that the number inserted be in a range of long.
I cannot use RangeValidator because long is not a supported type, and in
addition I wanted to learn to develop a Custom Validator control.

Everything worked fine until I tryied to add 2 different
LongRangeValidator
controls on the same page, with 2 different ranges. The problem is that
my
ClientValidationFunction is built at runtime with the range limits
stamped
in it, that results in the following code rendered:

function ClientLongRangeValidation(source, arguments) {
arguments.IsValid = false;
if (!isNaN(arguments.Value)) {
var val = arguments.Value
if (arguments.Value >= -9223372036854775808 && arguments.Value <=
9223372036854775807)
arguments.IsValid = true;
}
}

I see that the normal RangeValidator control adds some interesting rows
at
the bottom of the page:
var gnIB1_ctl02 = document.all ? document.all["gnIB1_ctl02"] :
document.getElementById("gnIB1_ctl02");
gnIB1_ctl02.controltovalidate = "gnIB1_gnTxt1";
gnIB1_ctl02.type = "Integer";
gnIB1_ctl02.evaluationfunction = "RangeValidatorEvaluateIsValid";
gnIB1_ctl02.maximumvalue = "2147483647";
gnIB1_ctl02.minimumvalue = "0";

While CustomValidator just adds the following:
var gnIB2_ctl02 = document.all ? document.all["gnIB2_ctl02"] :
document.getElementById("gnIB2_ctl02");
gnIB2_ctl02.controltovalidate = "gnIB2_gnTxt2";
gnIB2_ctl02.errormessage = "Invalid. Min:-9223372036854775808, max:
9223372036854775807";
gnIB2_ctl02.evaluationfunction = "CustomValidatorEvaluateIsValid";
gnIB2_ctl02.clientvalidationfunction = "ClientLongRangeValidation";

It's seems that if I could add a minimumvalue and a maximumvalue fields
for
each control, I could write a different client function that would work
with
as many controls I'd like.

But how can I add "javascript fields"?
I see that CustomValidator inherits RegisterValidatorCommonScript and
RegisterValidatorDeclaration, but I don't think they're the right
methods.

Any help would be appreciated, Thanks.
Paolo Benetti.
 
A

Alessandro Zifiglio

your more than welcome, Paolo.
Have a good day,
Alessandro Zifiglio
http://www.AsyncUI.net

Paolo said:
Hi Alessandro,

you saved me from insanity.
It works perfectly now.

Many thanks,
Paolo.


Alessandro Zifiglio said:
hi Paolo, you can register you two propertis as expando attributes. The
method you are looking for is RegisterExpandoAttribute.

http://msdn2.microsoft.com/en-us/library/ms153123.aspx

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net


Paolo Benetti said:
Dear all,

I'm trying to add a CustomValidator that must validate a TextBox,
ensuring
that the number inserted be in a range of long.
I cannot use RangeValidator because long is not a supported type, and in
addition I wanted to learn to develop a Custom Validator control.

Everything worked fine until I tryied to add 2 different
LongRangeValidator
controls on the same page, with 2 different ranges. The problem is that
my
ClientValidationFunction is built at runtime with the range limits
stamped
in it, that results in the following code rendered:

function ClientLongRangeValidation(source, arguments) {
arguments.IsValid = false;
if (!isNaN(arguments.Value)) {
var val = arguments.Value
if (arguments.Value >= -9223372036854775808 && arguments.Value <=
9223372036854775807)
arguments.IsValid = true;
}
}

I see that the normal RangeValidator control adds some interesting rows
at
the bottom of the page:
var gnIB1_ctl02 = document.all ? document.all["gnIB1_ctl02"] :
document.getElementById("gnIB1_ctl02");
gnIB1_ctl02.controltovalidate = "gnIB1_gnTxt1";
gnIB1_ctl02.type = "Integer";
gnIB1_ctl02.evaluationfunction = "RangeValidatorEvaluateIsValid";
gnIB1_ctl02.maximumvalue = "2147483647";
gnIB1_ctl02.minimumvalue = "0";

While CustomValidator just adds the following:
var gnIB2_ctl02 = document.all ? document.all["gnIB2_ctl02"] :
document.getElementById("gnIB2_ctl02");
gnIB2_ctl02.controltovalidate = "gnIB2_gnTxt2";
gnIB2_ctl02.errormessage = "Invalid. Min:-9223372036854775808, max:
9223372036854775807";
gnIB2_ctl02.evaluationfunction = "CustomValidatorEvaluateIsValid";
gnIB2_ctl02.clientvalidationfunction = "ClientLongRangeValidation";

It's seems that if I could add a minimumvalue and a maximumvalue fields
for
each control, I could write a different client function that would work
with
as many controls I'd like.

But how can I add "javascript fields"?
I see that CustomValidator inherits RegisterValidatorCommonScript and
RegisterValidatorDeclaration, but I don't think they're the right
methods.

Any help would be appreciated, Thanks.
Paolo Benetti.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top