Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Compare Validator Control

Compare Validator Control

Scheduled Pinned Locked Moved ASP.NET
helptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rajiya
    wrote on last edited by
    #1

    Hi, I have 2 textboxes one is txtStartTime and the other is txtEndtime. Compare Validator is not Working for these 2 textboxes.I am storing DateTime values in both the textboxes. I want to check if EndTime is Greater then StartTime.If StartTime is Greater then Endtime then It should give an error message saying StartTime cannot be greater then EndTime. Plz suggest me how to do it. thanks, riz

    C M 2 Replies Last reply
    0
    • R Rajiya

      Hi, I have 2 textboxes one is txtStartTime and the other is txtEndtime. Compare Validator is not Working for these 2 textboxes.I am storing DateTime values in both the textboxes. I want to check if EndTime is Greater then StartTime.If StartTime is Greater then Endtime then It should give an error message saying StartTime cannot be greater then EndTime. Plz suggest me how to do it. thanks, riz

      C Offline
      C Offline
      chakkara2003
      wrote on last edited by
      #2

      use a compare validator to validate two dates. add one comparevalidator on properties select controltocompare,controltovalidate and value to compare. give value as >, < and change the type property into date this wil fulfil ur requirement, if any error let me know coolsweety

      1 Reply Last reply
      0
      • R Rajiya

        Hi, I have 2 textboxes one is txtStartTime and the other is txtEndtime. Compare Validator is not Working for these 2 textboxes.I am storing DateTime values in both the textboxes. I want to check if EndTime is Greater then StartTime.If StartTime is Greater then Endtime then It should give an error message saying StartTime cannot be greater then EndTime. Plz suggest me how to do it. thanks, riz

        M Offline
        M Offline
        Mike Ellison
        wrote on last edited by
        #3

        I think you would also want to check that valid dates have been entered. Does this help?

        <% @Page Language="C#" %>

        <html>
        <head>
        <title>Validating Dates</title>
        </head>

        <body>
        <form runat="server">

            Start:  <asp:TextBox id="txtStartDate" runat="server" />
            <br />
            End:  <asp:TextBox id="txtEndDate" runat="server" />
            <br />
            <asp:CompareValidator id="valid1" runat="server"
                                  ControlToValidate="txtStartDate"
                                  Type="Date"
                                  Operator="DataTypeCheck"
                                  Text="The start date must be a valid date."
                                  />        
            <asp:CompareValidator id="valid2" runat="server"
                                  ControlToValidate="txtEndDate"
                                  Type="Date"
                                  Operator="DataTypeCheck"
                                  Text="The end date must be a valid date."
                                  />        
            <asp:CompareValidator id="valid3" runat="server"
                                  ControlToValidate="txtStartDate"
                                  ControlToCompare = "txtEndDate"
                                  Type="Date"
                                  Operator="LessThanEqual"
                                  Text="The start date must be less than 
                                         or equal to the end date"
                                  />
            <br />
            <br />
            <asp:Button runat="server" text="Submit" />                              
            
        
        </form>    
        

        </body>

        </html>

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups