Validators at cross purposes?

Discussion in 'ASP .Net' started by Ken McAndrew, Jan 5, 2004.

  1. Ken McAndrew

    Ken McAndrew Guest

    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))


    --
    Kenneth S. McAndrew
    Software Developer, Information Concepts
     
    Ken McAndrew, Jan 5, 2004
    #1
    1. Advertising

  2. Ken McAndrew

    Scott Allen Guest

    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

    On Mon, 5 Jan 2004 14:48:41 -0500, "Ken McAndrew"
    <> wrote:

    >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))
     
    Scott Allen, Jan 5, 2004
    #2
    1. Advertising

  3. Ken McAndrew

    Ken McAndrew Guest

    That did the trick. Thanks for the help.

    --
    Kenneth S. McAndrew
    Software Developer, Information Concepts



    "Scott Allen" <bitmask@[nospam].fred.net> wrote in message
    news:...
    > 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
    >
    > On Mon, 5 Jan 2004 14:48:41 -0500, "Ken McAndrew"
    > <> wrote:
    >
    > >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))

    >
     
    Ken McAndrew, Jan 6, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ratman
    Replies:
    0
    Views:
    715
    Ratman
    Sep 14, 2004
  2. Edwin Knoppert
    Replies:
    3
    Views:
    385
    Edwin Knoppert
    Jan 27, 2006
  3. =?Utf-8?B?ZGF2ZS5kb2xhbg==?=

    Tree View for Non-Navigational Purposes

    =?Utf-8?B?ZGF2ZS5kb2xhbg==?=, Mar 19, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    3,250
    =?Utf-8?B?ZGF2ZS5kb2xhbg==?=
    Mar 20, 2006
  4. =?Utf-8?B?RGFiYmxlcg==?=

    use same DetailsView for multiple purposes?

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 28, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    4,146
    =?Utf-8?B?RGFiYmxlcg==?=
    Mar 29, 2006
  5. Replies:
    8
    Views:
    370
    Steven D'Aprano
    May 15, 2005
Loading...

Share This Page