Results 1 to 4 of 4

Thread: Texbox - CompareValidate

  1. #1

    Thread Starter
    Hyperactive Member buddu's Avatar
    Join Date
    Jul 2001
    Location
    India
    Posts
    446

    Texbox - CompareValidate

    I have 2 textboxes like
    NoDays_____ SanctionedDays____

    NoDays Default value=5. NOw i want to Compare the SanctionedDays like (san.days < NoDays) and sanctionDays Textbox has to allowe only Numeric Data.
    For this I have writeen a validaions as follows.

    My Question is Once the RegularExpre.. validation is satisfy then only it has to go Compare validaion. Because when i enter SanctionedDays="AA" it is displaying both error messages..?
    Texbox Code
    Code:
    <Asp:Textbox id="txtNoDays" BackColor="Gainsboro" ReadOnly="True" Runat="server" size="10"/>
    
    <Asp:Textbox id="txtSanDays" Runat="server" size="10" MaxLength="3"/>
    my Validation Code
    Code:
    <asp:CompareValidator id="comp1" ControlToValidate="txtNoDays" ControlToCompare = "txtSanDays" Type="String" Operator="GreaterThanEqual" Text="Sanctioned days should be less than days requested!" runat="server"/>
            <asp:RegularExpressionValidator ControltoValidate="txtSanDays" Display="Dynamic" ErrorMessage="Enter Numeric data" ValidationExpression="\d" Runat="Server" />
    How to do this? how to validate one after one?
    prasad

  2. #2
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    Your controls will fail on both counts if you enter "AA" because it is not a number and it can't be calculated to be greater than or equal to the other control. You can leave out the regular expression validator because the compare validator will return an error if the SanctionedDays is not a number.

  3. #3

    Thread Starter
    Hyperactive Member buddu's Avatar
    Join Date
    Jul 2001
    Location
    India
    Posts
    446
    But i need to maintain both. How will u do?
    prasad

  4. #4
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    I still don't understand the need for both. If this validator:-

    <asp:CompareValidator id="comp1" ControlToValidate="txtNoDays" ControlToCompare = "txtSanDays" Type="String" Operator="GreaterThanEqual" Text="Sanctioned days should be less than days requested!" runat="server"/>

    returns true then the Sanctioned days has a number in it. Checking it a second time with a regular expression validator is unecessary. Perhaps I'm misunderstaning you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width