RadDatePIcker MinDate

8 posts, 0 answers
  1. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 09 Oct 2009 Link to this post

    Hi.

     

    I’ve been looking at your sample for validating a Raddatepicker:-

    http://demos.telerik.com/aspnet-ajax/calendar/examples/datepicker/validation/defaultcs.aspx

     

    This is my scenario:

    I have a raddatepicker and the mandate=”01/01/2009” this works great of course if I want to prompt the user that the date is incorrect, however I can still submit the form.

     

    I then put a compare validator on the page and set that to Greater than or equal to “01/01/2009”, for some reason it won’t work.

     

    Basically I want to prevent the user from submitting the form if the date is less than “01/01/2009” am I missing something?

     

    Thanks

    Karl

  2. Dimo
    Admin
    Dimo avatar
    8332 posts

    Posted 09 Oct 2009 Link to this post

    Hello Karl,

    The DatePicker internally stores its selected date in the following culture-independent format:

    yyyy-mm-dd
    for example:
    2009-10-09

    The value which the CompareValidator receives during validation is in the above format. So I suppose you need to adjust the format of the compare expression.

    Kind regards,
    Dimo
    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. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 09 Oct 2009 Link to this post

    Hi,

    Tried your sugestion and still the same,
       <div> 
                <telerik:RadDatePicker ID="RadDatePicker1" runat="server" MinDate="2009-01-01">  
                    <Calendar UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x">  
                    </Calendar> 
                    <DatePopupButton HoverImageUrl="" ImageUrl="" /> 
                </telerik:RadDatePicker> 
                &nbsp;<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="RadDatePicker1" 
                    ErrorMessage="This format 2009-01-01" Operator="GreaterThanEqual" Type="Date" 
                    ValueToCompare="2009-01-01"></asp:CompareValidator></div


    Thanks
  5. Dimo
    Admin
    Dimo avatar
    8332 posts

    Posted 09 Oct 2009 Link to this post

    Hello Karl,

    Your code is correct, but I forgot to explain something else. Actually, when the RadDatePicker textbox holds an out-of-range date, its value is empty. As a result, the CompareValidator does not validate anything and you are able to postback.

    Either add a RequiredFieldValidator, or remove the RadDatePicker's MinDate property.

    Greetings,
    Dimo
    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.
  6. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 09 Oct 2009 Link to this post

    Hi,

    Thanks, this isn't a required field, I just don't want to allow dates below 01/01/2009.

    Is there anyother way?

    Thanks
  7. Dimo
    Admin
    Dimo avatar
    8332 posts

    Posted 09 Oct 2009 Link to this post

    Hello Karl,

    Well, then leave the picker's MinDate property as it is, and use a CustomValidator, which should check whether there is an invalid date inside the picker's textbox and alert the user. If picker.get_selectedDate() returns null, but picker.get_dateInput()._textBoxElement.value is not empty, then you have an invalid date.

    Regards,
    Dimo
    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.
  8. Daniel
    Daniel avatar
    1 posts
    Member since:
    Nov 2010

    Posted 27 Jan in reply to Dimo Link to this post

    could you please provide an c# example of the "CustomValidator"

     thx

  9. Eyup
    Admin
    Eyup avatar
    3012 posts

    Posted 01 Feb Link to this post

    Hello Daniel,

    Generally, you can use the default ASP.NET custom validator:
    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator%28v=vs.110%29.aspx


    I am also sending a sample web site to demonstrate a practical implementation with a compare validator.

    Regards,
    Eyup
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017