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

Q2 2010 Fixed: RadDatePicker client validation with ASP validators when an invalid value is entered

8 Answers 105 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Andrew Zhao
Top achievements
Rank 1
Andrew Zhao asked on 08 Sep 2010, 09:25 PM
I noticed the release statement in Q2 2010.
  • Fixed: RadDatePicker client validation with ASP validators when an invalid value is entered.
  • Does it mean that RadDatePicker would support ASP CompareValidator with Operator="DataTypeCheck" as Date, or support PeterBlum's DataTypeCheckValidator?

    8 Answers, 1 is accepted

    Sort by
    0
    Dimo
    Telerik team
    answered on 09 Sep 2010, 10:12 AM
    Hi Andrew Zhao,

    The fix is related to the case when you enter a valid date and then enter an invalid date. In that case with the old RadControls version the validation passed, which was incorrect.

    So I am afraid the answer to your question is "no".

    RadDatePicker stores and reports its value to external components (e.g. validators) in the following culture-independent format:

    yyyy-MM-dd-HH-mm-ss

    If a given validator can recognize this string as a date, validation will work with a Date type. Otherwise you will need to validate the picker value as a string or use a custom validator and retrieve/validate the picker value by using its client API (the get_selectedDate() method).

    Regards,
    Dimo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    0
    Matt
    Top achievements
    Rank 1
    answered on 21 Sep 2012, 05:11 PM
    I think having the RadDatePicker work with the asp.net CompareValidator to ensure that a valid date was entered is something that many developers could use. It seems like a major oversight. It would simplify our lives. :-)
    0
    Vasil
    Telerik team
    answered on 24 Sep 2012, 07:04 AM
    Hi Matt,

    The RadDatePicker (RadDateInput in particular) can work with the CompareValidator. You need to use string comparison and it will work correct.
    It is exact the reason we use  "yyyy-MM-dd-HH-mm-ss" format. In this format you can be sure that comparing the string representations of given dates will return the same result as comparing the dates. This also resolves the issues in different cultures and different time zones between the browser and the server.

    If the date entered in the date input is invalid, it's ValidationValue will remain empty string. So if the validation string is not empty, you can be sure that is it representation of valid date. Then you can compare it with other string.

    All the best,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
    0
    James
    Top achievements
    Rank 1
    answered on 15 Jan 2013, 01:27 PM
    Is it possible to get an example of how to set up the CompareValidator to make this comparison?  I am not sure I understand how to do this.  Thanks in advance for your help.
    James
    0
    Vasil
    Telerik team
    answered on 15 Jan 2013, 03:57 PM
    Hello James,

    See this online demo:
    http://demos.telerik.com/aspnet-ajax/input/examples/common/validation/defaultcs.aspx

    Here is an example:
    <telerik:RadDateInput ID="RadDateInput1" runat="server" DateFormat="d" MinDate="01/01/1990" MaxDate="01/01/3000"></telerik:RadDateInput>
     
    <asp:RangeValidator ID="DateInputRangeValidator" runat="server" ControlToValidate="RadDateInput1"
    ErrorMessage="Choose a date between 5th of January 2005 and 1st of September 2005"
    Display="Dynamic" MaximumValue="2005-09-01-00-00-00" MinimumValue="2005-01-05-00-00-00"></asp:RangeValidator>


    All the best,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
    0
    James
    Top achievements
    Rank 1
    answered on 15 Jan 2013, 05:25 PM
    Vasil,

    Thanks for the quick response.  I am trying to validate a raddatepicker and I was hoping that this example would work but it does not appear to.  I want to leave the control both pickable through the icon for setting as well as editable through the textbox.  This is so the user can delete the date if necessary. 

    The date is not required so I also want to be able to postback (save) the form with the date field empty.  What I do want to be able to do after all of this is make sure that any text entered through the textbox represents a correctly formatted date and stop the postback if it is not.  I want to use an asp.net validator in conjunction with an AJAX ValidatorCalloutExtender so that I can display the error message in the same "bubble" format as the rest of the pages. 

    Would you please take a look at my code example below and see where I am going wrong?
    Thanks in advance,

    James
    <telerik:RadDatePicker ID="rdpStoreNewOpenDate" runat="server" Culture="en-US" DbSelectedDate='<%# Bind("NewOpenDate") %>' ShowPopupOnFocus="True" Skin="Simple"><Calendar Skin="Simple" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x"></Calendar><DateInput DateFormat="M/d/yyyy" DisplayDateFormat="M/d/yyyy" /><DatePopupButton HoverImageUrl="" ImageUrl="" /></telerik:RadDatePicker>
    <asp:RangeValidator runat="server" ID="rvRDPStoreNewOpenDate" ControlToValidate="rdpStoreNewOpenDate" MinimumValue="1980-01-01-12-00-00" MaximumValue="2099-12-30-12-00-00" ErrorMessage="Please provide a valid date." Display="Dynamic"></asp:RangeValidator>
    <ajaxToolkit:ValidatorCalloutExtender ID="vceRVRDPStoreNewOpenDate" runat="server" TargetControlID="rvRDPStoreNewOpenDate"/>
    0
    James
    Top achievements
    Rank 1
    answered on 17 Jan 2013, 12:54 PM
    Anybody?  Any ideas on how to validate?
    0
    Vasil
    Telerik team
    answered on 18 Jan 2013, 09:56 AM
    Hi James,

    The RadDatePicker auto-corrects the invalid out of range dates. And if they are not in the range, it's value will be null. If you want to use asp:RangeValidator without RequiredFieldValidator it will be best to set such range to the DatePicker, to allow dates in all range to be entered.

    This way if you enter value like 1950, it will remain valid for the picker itself, but the validator will validate it. If you use MinDate for the picker the same as the validator, the picker will set value for all other dates as null, and they will be not validated by the validator.

    <telerik:RadDatePicker ID="picker1" runat="server"
        MinDate="0/0/0" MaxDate ="1/1/2099">
     
    </telerik:RadDatePicker>
    <asp:RangeValidator runat="server" ControlToValidate="picker1"
        MinimumValue="1980-01-01-12-00-00"
        MaximumValue="2099-12-30-12-00-00"
        Text="Please provide a valid date.">


    Regards,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
    Tags
    Calendar
    Asked by
    Andrew Zhao
    Top achievements
    Rank 1
    Answers by
    Dimo
    Telerik team
    Matt
    Top achievements
    Rank 1
    Vasil
    Telerik team
    James
    Top achievements
    Rank 1
    Share this question
    or