RadDatePicker validation

Thread is closed for posting
4 posts, 0 answers
  1. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 28 Sep 2009 Link to this post

    I have two date pickers that I am trying to validate for a start and end date. I have this in my code but it always returns back as an invalid entry, even when the end date is later than the start date. Any ideas why? Here is my code. Thanks,
            <tr>
                <td>
                    <center>
                        <span class="adminTableLabel">Start Date</span>
                        <telerik:RadDateTimePicker ID="startDate" Skin="Web20" runat="server" Width="150px">
                        </telerik:RadDateTimePicker>
                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" ControlToValidate="startDate"
                            ErrorMessage="Please enter a start date." CssClass="errorMessage"></asp:RequiredFieldValidator>
                    </center>
                </td>
                <td class="addBusinessSpacing">
                </td>
                <td>
                    <center>
                        <span class="adminTableLabel">End Date</span>
                        <telerik:RadDateTimePicker ID="endDate" Skin="Web20" runat="server" Width="150px">
                        </telerik:RadDateTimePicker>
                        <asp:CompareValidator ID="dateCompareValidator" runat="server"
                            ControlToValidate="endDate" ControlToCompare="startDate"
                            Operator="GreaterThan" Type="date"
                            ErrorMessage="The end date must be later than the start date."
                            CssClass="errorMessage">
                        </asp:CompareValidator>
                    </center>
                </td>
            </tr>
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 29 Sep 2009 Link to this post

    Hello,

    Please review the following online demo which shows a sample period selection page.  The user has to enter two dates, the second one being after the first.
    We are using two RequiredFieldValidator instances to ensure the date pickers are not left empty.  A CompareValidator ensures that the second date is greater than the first one.
    Validation

    I hope this helps.

    Regards,
    Pavlina
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 29 Sep 2009 Link to this post

    So I have done this, but my date always errors even when enddate is greater than start date. Here is my code
            <tr>
                <td>
                    <center>
                        <span class="adminTableLabel">Start Date</span>
                        <telerik:RadDateTimePicker ID="startDate" Skin="Web20" runat="server" Width="150px">
                        </telerik:RadDateTimePicker>
                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" ControlToValidate="startDate"
                            ErrorMessage="Please enter a start date." CssClass="errorMessage" Display="Dynamic"></asp:RequiredFieldValidator>
                    </center>
                </td>
                <td class="addBusinessSpacing">
                </td>
                <td>
                    <center>
                        <span class="adminTableLabel">End Date</span>
                        <telerik:RadDateTimePicker ID="endDate" Skin="Web20" runat="server" Width="150px">
                        </telerik:RadDateTimePicker>
                        <asp:RequiredFieldValidator runat="server" ID="Requiredfieldvalidator2" ControlToValidate="endDate"
                        ErrorMessage="Please select an end date." Display="Dynamic"></asp:RequiredFieldValidator>
                        <asp:CompareValidator ID="dateCompareValidator" runat="server"
                            ControlToValidate="endDate" ControlToCompare="startDate"
                            Operator="GreaterThan" Type="date"
                            ErrorMessage="The end date must be later than the start date."
                            CssClass="errorMessage" Display="Dynamic">
                        </asp:CompareValidator>
                    </center>
                </td>
            </tr>
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 30 Sep 2009 Link to this post

    Hi,

    You need to set the Type property of the CompareValidator to "String" in order to work with a RadDateTimePicker or RadTimePicker control .  When working with RadDatePicker the property must be set to "Date".

    Let me know if you need additional assistance.

    Best wishes,
    Pavlina
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top