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

RadDatePIcker MinDate

7 Answers 1719 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 09 Oct 2009, 11:26 AM

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

7 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 09 Oct 2009, 01:07 PM
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.
0
Karl
Top achievements
Rank 1
answered on 09 Oct 2009, 03:21 PM
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
0
Dimo
Telerik team
answered on 09 Oct 2009, 03:28 PM
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.
0
Karl
Top achievements
Rank 1
answered on 09 Oct 2009, 03:42 PM
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
0
Dimo
Telerik team
answered on 09 Oct 2009, 04:05 PM
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.
0
Daniel
Top achievements
Rank 1
answered on 27 Jan 2016, 10:57 AM

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

 thx

0
Eyup
Telerik team
answered on 01 Feb 2016, 11:44 AM
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
Tags
Calendar
Asked by
Karl
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Karl
Top achievements
Rank 1
Daniel
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or