RadDatePicker cannot be validated against ValueToCompare

6 posts, 0 answers
  1. GrievousAngel
    GrievousAngel avatar
    10 posts
    Member since:
    Oct 2007

    Posted 21 Nov 2007 Link to this post

    I am trying to set up a CompareValidator against the RadDatePicker because the MinDate setting does not prevent a user typing in a date that is below that date. The control does provide a visual indication that the date entered is not in the correct range.

    I am using the ValueToCompare property on the CompareValidator to perform this validation but it does not work. The declaration I'm using is :
    <asp:ValidationSummary ID="validationSummary" runat="server" /> 
    <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
    <telerik:RadDatePicker ID="rdpControl" MinDate="1900-01-01" runat="server" /> 
    <asp:CompareValidator ID="dateValidator"   
        ControlToValidate="rdpControl"   
        Display="Dynamic"   
        ErrorMessage="Failed"   
        Type="Date"   
        Operator="GreaterThanEqual" 
        ValueToCompare="1900-01-01" 
        runat="server" /> 
    <asp:Button ID="btnPostback" Text="Validate" runat="server" /> 

    Should this work, or is there a known issue ? I am using Visual Studio 2008 Beta 2 and Prometheus v1107.

    Regards, Nick
  2. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 26 Nov 2007 Link to this post

    Hi,

    Actually, the control should indicate that there has been an erroneous date entered (less than the min date for example). This is demonstrated in the screenshot attached to this message.
    Other than that, you can use the client side OnError event handler, to re-set the text, or remove it. Additional information on the client events for the control is available in the following article.
    I hope this information helps.

    Best wishes,
    Yavor
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. GrievousAngel
    GrievousAngel avatar
    10 posts
    Member since:
    Oct 2007

    Posted 26 Nov 2007 Link to this post

    Yavor,

    Yes my control also displayed the visual indication that the date was below the minimum date, but I had hoped that a CompareValidator used against the RadDatePicker would also flag it as invalid.

    Thanks for the pointers to the client events as it looks like I'll have to manually set the CompareValidator as invalid in that event.

    Regards, Nick
  4. GrievousAngel
    GrievousAngel avatar
    10 posts
    Member since:
    Oct 2007

    Posted 26 Nov 2007 Link to this post

    Having played around wih this over the last few hours I have concluded that it is difficult to achieve what I wanted, i.e. to set the validator to invalid in clientside scripts. This is because, although I can attach to the OnDateError event, I do not seem to be able to get at the validators associated with the RadDatePicker.

    I then thought I'd just do the next best thing and validate this server side on a postback, but much to my annoyance I cannot find a server property on the RadDatePicker that signifies that the date is outside the min and max range. What have I missed, is there a property such as 'IsValid' ?

    Regards, Nick
  5. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 27 Nov 2007 Link to this post

    Hello,

    If there is a min date, for the control, you can remove it, so that it would allow the user to enter a date, and in this case the CompareValidator would evaluate the user input. I tested with the following code:

    .aspx
     <form id="form1" runat="server">   
        <asp:ScriptManager ID="ScriptManager1" runat="server" />      
              
            <telerik:RadDatePicker ID="rdpControl" MinDate="0001-01-01" runat="server" /> 
            <asp:CompareValidator ID="dateValidator" ControlToValidate="rdpControl" Display="Dynamic" 
                ErrorMessage="Failed" Type="Date" Operator="GreaterThanEqual" ValueToCompare="1900-01-01" 
                runat="server" /> 
            <asp:Button ID="btnPostback" Text="Validate" runat="server" OnClick="btnPostback_Click" /> 
        </form> 

    Either this, or you can use the client side onError event.

    Kind regards,
    Yavor
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. GrievousAngel
    GrievousAngel avatar
    10 posts
    Member since:
    Oct 2007

    Posted 27 Nov 2007 Link to this post

    Yavor, 

    I used your workaround and the ability to set the Max and Min DateRanges on the Calendar in the DatePicker to achieve the results I needed.

    Thanks very much for persevering. Nick
Back to Top