asp.netvalidationcomparevalidator

using CompareValidator compare 2 times


I have 2 inputs:

<label for="timeStart">Start Time:</label>
  <input id="timeStart" value="10:00" type="text" runat="server" clientidmode="static" />
<label  for="timeEnd">End Time:</label>
  <input id="timeEnd" value="16:00" type="text" runat="server" clientidmode="static" />

and comparer validator inline with submit button

<input class="btn" id="save" value="CREATE Object" type="submit" runat="server" 
  ValidationGroup="save"/>
<asp:CompareValidator id="CompareTimes" 
                      runat="server" 
                      ControlToCompare="timeStart"
                      ControlToValidate="timeEnd" 
                      ForeColor="Red" Display="Dynamic"
    ErrorMessage="The End Time must be later than the Start Time." 
                      Type="Date" 
                      Operator="GreaterThan" 
                      ValidationGroup="save"/>

in all case it gave me error message, what I do wrong?


Solution

  • Your inputs are client side controls. If you would like to use <asp:CompareValidator.../> you have to use server side label controls such: <asp:Lable runat="server".../>.

    If you would like to use these (client side) input labels you have to compare them by JavaScript on the client side.