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

DatePicker Runtime Error when Date is outside of Min/Max date

8 Answers 902 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
B
Top achievements
Rank 1
B asked on 04 Jul 2011, 03:50 PM
I add datepicker to webform
set min date to 1/1/1900
set max date to 12/31/2099
user opens webform on existing record with date of 1/15/2300 (outside min/max date)
a runtime error occurs.

Question(s):
Why the runtime error?  this is causing us grief.  why doesn't validation just trigger on the datepicker control and display a validation error in the ui? 
If i add the datepicker to 100s of forms, do i really have to add try/catch error handling for each when setting the date value of the control? this is a real pain.



8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Jul 2011, 07:36 AM
Hello,

One suggestion is to check the date before setting it as the selected value.
C#:
if((date>RadDatePicker1.MinDate) && (date<RadDatePicker1.MaxDate))
     RadDatePicker1.SelectedDate = date;

Thanks,
Shinu.
0
B
Top achievements
Rank 1
answered on 06 Jul 2011, 06:36 PM
Thanks for the suggestion.  but this is exactly what i was hoping not to have to do.  we have 100s of forms that would need updating.  this appears to be a behavior issue with the control that i wish could be disabled...where it wouldn't throw a runtime error, but just trigger validation error on save.
0
Tsvetoslav
Telerik team
answered on 12 Jul 2011, 04:34 PM
Hi Brian,

The observed behavior is actually no issue with the date-picker control but a piece of design logic that has its purpose and intention. Suppose, for example, that a developer has attached a click event handler to a button control. In the click event handler he is setting the new date to the date-picker control and upon that uses the new entry to execute some other business requirement such as updating a database with the new date or loading data into a grid control that is filtered by the new date. If we were to throw no exception upon a new invalid date being set all the subsequent business logic will fail and the application will behave abnormally.

Besides, that's probably exactly what some of our clients have implemented in their project and as a result they are counting on the date-picker control to throw the exception in question - so we are also running the risk of introducing breaking changes into their applications if we were to change the picker SelectedDate setter along the lines of your requirement. 

Thanks for the undestanding.

Regards,
Tsvetoslav
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
B
Top achievements
Rank 1
answered on 12 Jul 2011, 07:00 PM
Let's turn this around.  Suppose you have an existing database where data was entered outside of your control - e.g. when customers migrate to our software we import their data from legacy systems.  We have to allow all dates to be imported...even bad ones that SQL server will accept.  Now we implement your datepicker control.  and BAM - it throws a ton of exceptions.  A much more preferred behavior would be to give us a switch to ignore the behaviour so an exception isn't thrown or just catch the error during forms validation.  your datepicker is unusable to us due to this issue.
0
Tsvetoslav
Telerik team
answered on 14 Jul 2011, 04:51 PM
Hello Brian,

Could you give me more details on what is supposed to happen after the exception is ignored - should the new invalid date be displayed in the date-picker despite all and if so, should it have the invalid date style (yellow color with a exclamation mark triangle) or should the date-picker be left blank. I need this information so that our development team can make an informed decision on the possible implementation of your requirement.

Regards,
Tsvetoslav
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
B
Top achievements
Rank 1
answered on 17 Jul 2011, 01:16 AM
Yes, an invalid date style would be perfect.  It would be great if you would still display the date in the control.  That way during editing on a webform, it would visually inform the end user that the date is obviously bad and it would be caught by the page validation if they attempt to save.  and again...assuming it's a valid date datatype...allow the developer to ignore the date when assigning/binding it to the control from the database.  that would be an AWESOME behaviour and would make your min/max date setting extremely useful.  Thanks for your consideration!
0
Tsvetoslav
Telerik team
answered on 18 Jul 2011, 03:17 PM
Hello Brian,

I am glad to inform you that the feature required by you has been implemeted into the RadDatePicker and RadDateInput controls. Now they sport a SkipMinMaxDateValidationOnServer property that if switched on should produce the behavior you desire.

The new improvement will be available in the next latest internal build that should come out by the end of the day tomorrow.

Regards,
Tsvetoslav
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
B
Top achievements
Rank 1
answered on 26 Jul 2011, 04:51 AM
you guys are truely awesome.  thank you!
Tags
General Discussions
Asked by
B
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
B
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or