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

[Solved] Error when Value = MaxDate

1 Answer 97 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Wade
Top achievements
Rank 1
Wade asked on 21 Feb 2010, 08:26 PM
I have the following code in my view.
<%= Html.Hidden("UserId", ViewData["userId"], new { UserId = ViewData["userId"] })%>
<label for="DatePicker-input">Task Entry Date (Required)</label>
<%= Html.Telerik()
                        .DatePicker()
                        .Name("selDate")
                        .MinDate((DateTime)ViewData["prgmStartDate"])
                        .MaxDate((DateTime)ViewData["prgmEndDate"])
                        .Value((DateTime)ViewData["prgmDefDate"])
%>
<%= Html.ValidationMessage("selDate", "*")%>

If I feed the DatePicker a dates from the Controller,where occasionally .MaxDate = .Value occurs.  (In my case, its where the program date is the same date as today, or today is past the program date, either of which I set the value in the controller to be the same date as the max).  When that occurs, you get the following error:

Specified argument was out of the range of valid values.
Parameter name: Date should be less than MinDate and bigger than MaxDate


To get around this, I am adding 23 hours to the end of the program date. So technically, Value is always < MaxDate.

Just thought I would let someone know.  Seems like a little bug to me.

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 22 Feb 2010, 10:04 AM
Hello Wade,

Thank you for pointing our attention to this erroneous behavior. Indeed this is a little flow in the settings verification. The fix will be applied in the official version.

Nevertheless if you need to fix it by your own, you can use this code patch:
private void VerifySettings()
{
    if (MinDate > MaxDate)
    {
        throw new ArgumentException(TextResource.MinDateShouldBeLessThanMaxDate);
    }
 
    if ((Value != null) && (MinDate > Value || Value > MaxDate))
    {
        throw new ArgumentOutOfRangeException(TextResource.DateOutOfRange);
    }
}

 The method is placed in the DatePicker.cs file in the Telerik.Web.MVC project.

Greetings,
Georgi Krustev
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.
Tags
Date/Time Pickers
Asked by
Wade
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or