This is a migrated thread and some comments may be shown as answers.

RadDatePicker validation

3 Answers 348 Views
UI for ASP.NET AJAX in ASP.NET MVC
This is a migrated thread and some comments may be shown as answers.
Web Services
Top achievements
Rank 2
Web Services asked on 28 Sep 2009, 06:19 PM
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>

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 29 Sep 2009, 08:00 AM
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.
0
Web Services
Top achievements
Rank 2
answered on 29 Sep 2009, 04:28 PM
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>
0
Pavlina
Telerik team
answered on 30 Sep 2009, 05:12 PM
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.
Tags
UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Web Services
Top achievements
Rank 2
Answers by
Pavlina
Telerik team
Web Services
Top achievements
Rank 2
Share this question
or