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

[Solved] DatePicker value not updated

6 Answers 122 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.
Dan
Top achievements
Rank 1
Dan asked on 25 Nov 2011, 07:51 PM
I have a model that has an End Date. I am trying to allow the user to select a "Current Date" or "No End Date" value by clicking a button to update the value in the datepicker. I am using an Editor Template to render the datepicker and the buttons (note that in my editor template I am also adjusting the date for time zones but that should not affect the outcome). In my controller (Edit post function) I look for the button name, update the end date value and then pass the model back to the view (without performing the update).

If I debug through the code I can see that the model contains the correct date and is assigning that date to the datepicker Value property, but the date does not change on the page. I am attaching the relevent files for your review.

I am fairly new to the MVC environment so any help that you can give would be appreciated.

Thanks.
Dan

6 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 30 Nov 2011, 08:58 AM
Hello Dan,

 
The code in the files looks OK. I will ask you to send us a simple test project. Thus I will be able to observe the problem locally and advice you further.

Best regards,
Georgi Krustev
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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Dan
Top achievements
Rank 1
answered on 30 Nov 2011, 07:38 PM
Hi Georgi,

I was able to recreate the problem in a scaled down project (attached).  Just click the Test button in the top right to launch the edit page.  If you click the Current Date button you will see that the button changes to No End Date but the value of the DatePicker does not change.  You can debug through the Editor Template for EndDate to see that it should have the current date value.

Hope you are able to find the problem.  Looking forward to hearing from you.

Thanks.
Dan
0
Georgi Krustev
Telerik team
answered on 05 Dec 2011, 03:34 PM
Hello Dan,

 
Thank you for the attached test project. After further investigation I believe the problem is related with the default behavior of the Html Helpers. Check this blog post for more information.
Let me know if I am missing something.

Best regards,
Georgi Krustev
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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Dan
Top achievements
Rank 1
answered on 05 Dec 2011, 07:09 PM
Hi Georgi,

I understand what you are referring to and believe that it makes sense.  However, I am still left with my original problem of providing functionality for my users to be able to easily switch from a "current date" value to a "no end date" value in the date picker.  Do you have any suggestions of how I could accomplish this?

Thanks.
Dan
0
Georgi Krustev
Telerik team
answered on 08 Dec 2011, 01:09 PM
Hi Dan,

 
You can use one of the suggestion mentioned in the article. What I can suggest you is to set the Model value:

<HttpPost()>
Function Edit(articleCategory As ArticleCategory) As ActionResult
    Dim TimeZone As String = "Pacific Standard Time"
 
    'If the CurrentDate or NoEndDate buttons have been clicked, return the current view
    If (Not String.IsNullOrEmpty(Request("CurrentDate"))) Then
        articleCategory.EndDate = Date.UtcNow
        ModelState.SetModelValue("EndDate", New ValueProviderResult(Date.UtcNow, Date.UtcNow, New System.Globalization.CultureInfo("en-US")))
        Return View(articleCategory)
    End If
 
    'If the CurrentDate or NoEndDate buttons have been clicked, return the current view
    If (Not String.IsNullOrEmpty(Request("NoEndDate"))) Then
        articleCategory.EndDate = New Date(2099, 12, 31, 0, 0, 0, 0, DateTimeKind.Local).ToUniversalTime
        ModelState.SetModelValue("EndDate", New ValueProviderResult(articleCategory.EndDate, articleCategory.EndDate, New System.Globalization.CultureInfo("en-US")))
        Return View(articleCategory)
    End If
 
    Return View(articleCategory)
End Function


Kind regards,
Georgi Krustev
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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Dan
Top achievements
Rank 1
answered on 08 Dec 2011, 07:11 PM
That worked great!  Thanks very much.
Dan
Tags
Date/Time Pickers
Asked by
Dan
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Dan
Top achievements
Rank 1
Share this question
or