CompareValidator control assistance

Discussion in 'ASP .Net' started by Groove, Aug 16, 2006.

  1. Groove

    Groove Guest

    I have a form that has several fields which accept integers. These fields
    are mileage fields so the value in the fields is easily in the hundreds of
    thousands. Ex: 152,750. The form loads existing data and lets users update
    it.

    When the form loads the data, I format it in the field as a "number" to make
    it easier to read like so:

    decMileage = drItemData("TotalMileage")
    txtMileage.Text = decMileage.ToString("n0")
    This will turn 152750 into 152,750 in the field and makes it much easier to
    read. To prevent the user from entering non-numeric characters, I have a
    CompareValidator with these fields. It checks the data type and makes sure
    it's an integer. The problem is the validator control doesn't like the
    commas in the value and can't validate it. It will still trigger the
    validator control.

    <asp:TextBox ID="txtMileage" runat="server" Columns="12" ToolTip="Total
    Milage" />

    <asp:RangeValidator ID="MileageValidator" runat="server"
    ControlToValidate="txtMileage" ErrorMessage="*Total Mileage must be numeric
    and between 1 and 9999999." MaximumValue="9999999" MinimumValue="1"
    SetFocusOnError="True" Type="Integer" >

    So can I have both? Can I format it upon page load with the comma and STILL
    allow the form to accept 999,999 as well as 999999?

    asp.net 2/vb



    Thanks!



    --
    Groove, Aug 16, 2006
    #1
    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. Eric Maia
    Replies:
    2
    Views:
    5,489
    Peter Blum
    Nov 18, 2004
  2. Chris Leffer

    DataTypeCheck in comparevalidator control

    Chris Leffer, May 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    6,029
  3. VancouverMike
    Replies:
    0
    Views:
    600
    VancouverMike
    Apr 11, 2008
  4. pc
    Replies:
    0
    Views:
    116
  5. Andres Aguiar

    Problem with CompareValidator control

    Andres Aguiar, Jul 28, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    270
    Steven Cheng[MSFT]
    Jul 29, 2004
Loading...

Share This Page