Validators at cross purposes?

K

Ken McAndrew

I'm working on a timesheet project that involves creating textboxes and
validators dynamically, and setting them in a placeholder to build a table.
The Regular Expression validator works fine, ensuring there are either 1 or
2 numbers, and then optionally a period and 1 or 2 numbers.

However, the Range Validator acts funny; I'm trying to have it ensure values
are between 0.01 and 24, and it works fine for values 2 or under. But when I
put 3 - 9 in, the validator fires like there is a mistake. But, if I use 03
instead of 3, it validates fine. I'm using different messages, so I know
it's the Range Validator causing this.

I've included the code I'm using to create the validators, and would
appreciate advice/opinions. I'm using VS.NET 2003 with the latest framework.
Thanks.

plcRange(intDIM, intCount) = New RangeValidator
plcRange(intDIM, intCount).ID = "rngTime_" & Year(DateNow) &
Month(DateNow) & intDIM & "_" & intCount
plcRange(intDIM, intCount).ControlToValidate = "txtTime_" &
Year(DateNow) & Month(DateNow) & intDIM & "_" & intCount
plcRange(intDIM, intCount).Display =
ValidatorDisplay.Dynamic
plcRange(intDIM, intCount).ErrorMessage = "++"
plcRange(intDIM, intCount).ForeColor = lblWidth.ForeColor
plcRange(intDIM, intCount).MinimumValue = 0.01
plcRange(intDIM, intCount).MaximumValue = 24.0
plcTable.Controls.Add(plcRange(intDIM, intCount))

plcValid(intDIM, intCount) = New RegularExpressionValidator
plcValid(intDIM, intCount).ID = "regTime_" & Year(DateNow) &
Month(DateNow) & intDIM & "_" & intCount
plcValid(intDIM, intCount).ControlToValidate = "txtTime_" &
Year(DateNow) & Month(DateNow) & intDIM & "_" & intCount
plcValid(intDIM, intCount).Display =
ValidatorDisplay.Dynamic
plcValid(intDIM, intCount).ErrorMessage = "**"
plcValid(intDIM, intCount).ForeColor = lblWidth.ForeColor
plcValid(intDIM, intCount).ValidationExpression =
"\d{1,2}([.]\d{1,2})?"
plcTable.Controls.Add(plcValid(intDIM, intCount))
 
S

Scott Allen

Hi Ken:

Set the validator's Type property to ValidationDataType.Double. The
default type is String, so the range validator must be doing a string
comparisons on the control values, and thus the strange results.

Hope this helps,
 
K

Ken McAndrew

That did the trick. Thanks for the help.

--
Kenneth S. McAndrew
Software Developer, Information Concepts
(e-mail address removed)


Scott Allen said:
Hi Ken:

Set the validator's Type property to ValidationDataType.Double. The
default type is String, so the range validator must be doing a string
comparisons on the control values, and thus the strange results.

Hope this helps,

--
Scott
http://www.OdeToCode.com

I'm working on a timesheet project that involves creating textboxes and
validators dynamically, and setting them in a placeholder to build a table.
The Regular Expression validator works fine, ensuring there are either 1 or
2 numbers, and then optionally a period and 1 or 2 numbers.

However, the Range Validator acts funny; I'm trying to have it ensure values
are between 0.01 and 24, and it works fine for values 2 or under. But when I
put 3 - 9 in, the validator fires like there is a mistake. But, if I use 03
instead of 3, it validates fine. I'm using different messages, so I know
it's the Range Validator causing this.

I've included the code I'm using to create the validators, and would
appreciate advice/opinions. I'm using VS.NET 2003 with the latest framework.
Thanks.

plcRange(intDIM, intCount) = New RangeValidator
plcRange(intDIM, intCount).ID = "rngTime_" & Year(DateNow) &
Month(DateNow) & intDIM & "_" & intCount
plcRange(intDIM, intCount).ControlToValidate = "txtTime_" &
Year(DateNow) & Month(DateNow) & intDIM & "_" & intCount
plcRange(intDIM, intCount).Display =
ValidatorDisplay.Dynamic
plcRange(intDIM, intCount).ErrorMessage = "++"
plcRange(intDIM, intCount).ForeColor = lblWidth.ForeColor
plcRange(intDIM, intCount).MinimumValue = 0.01
plcRange(intDIM, intCount).MaximumValue = 24.0
plcTable.Controls.Add(plcRange(intDIM, intCount))

plcValid(intDIM, intCount) = New RegularExpressionValidator
plcValid(intDIM, intCount).ID = "regTime_" & Year(DateNow) &
Month(DateNow) & intDIM & "_" & intCount
plcValid(intDIM, intCount).ControlToValidate = "txtTime_" &
Year(DateNow) & Month(DateNow) & intDIM & "_" & intCount
plcValid(intDIM, intCount).Display =
ValidatorDisplay.Dynamic
plcValid(intDIM, intCount).ErrorMessage = "**"
plcValid(intDIM, intCount).ForeColor = lblWidth.ForeColor
plcValid(intDIM, intCount).ValidationExpression =
"\d{1,2}([.]\d{1,2})?"
plcTable.Controls.Add(plcValid(intDIM, intCount))
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top