RadDateInput and CompareValidator

5 posts, 1 answers
  1. ADH
    ADH avatar
    45 posts
    Member since:
    Nov 2006

    Posted 18 Nov 2008 Link to this post

    Everything I've seen concerning this suggests that this code should validate correctly when your focus leaves RadDateInput2. Instead, valid dates which are later than the initial date produce errors - in fact, any valid date entered in the second box produces a validation error. What am I doing wrong?

    <%@ Page Language="C#" AutoEventWireup="true" Codebehind="Test.aspx.cs" Inherits="TestProject.Test" %> 
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
       <title>Untitled Page</title> 
    </head> 
    <body> 
       <form id="form1" runat="server"
          <div> 
             <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
             Date 1: 
             <telerik:RadDateInput ID="RadDateInput1" runat="server" SelectedDate="09/19/2008" /> 
             <br /> 
             <br /> 
             Date 2: 
             <telerik:RadDateInput ID="RadDateInput2" runat="server" /> 
             <br /> 
             <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Date 2 must be greater than or equal to date 1." 
                ControlToCompare="RadDateInput1" ControlToValidate="RadDateInput2" Type="Date" 
                Operator="GreaterThanEqual" /> 
          </div> 
       </form> 
    </body> 
    </html> 
     

  2. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 18 Nov 2008 Link to this post

    Hello Ashley,

    I suggest you examine our online demo illustrating an appropriate approach.
    Date Validation

    Let us know if you have additional questions.

    Regards,
    Daniel
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. ADH
    ADH avatar
    45 posts
    Member since:
    Nov 2006

    Posted 18 Nov 2008 Link to this post

    When I change the control from a DatePicker to a DateInput, the CompareValidator again fails to work. We are using DateInputs in our solution currently - is this the only solution, to switch to DatePickers?
  4. Answer
    Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 19 Nov 2008 Link to this post

    Hello Ashley,

    Please try to modify your CompareValidator as follows:
    <asp:CompareValidator  
      ID="dateCompareValidator"  
      runat="server"  
      ControlToValidate="RadDateInput2" 
      ControlToCompare="RadDateInput1"  
      Operator="GreaterThan"  
      ErrorMessage="The second date must be after the first one."
    </asp:CompareValidator> 

    I hope this helps.

    Regards,
    Daniel
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. ADH
    ADH avatar
    45 posts
    Member since:
    Nov 2006

    Posted 19 Nov 2008 Link to this post

    Bingo - apparently the type attribute covered something else entirely - DataTypeCheck value, I suppose. Thank you!
Back to Top