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

Date/Time Picker and Post

3 Answers 180 Views
UI for ASP.NET AJAX in ASP.NET MVC
This is a migrated thread and some comments may be shown as answers.
Cole
Top achievements
Rank 1
Cole asked on 03 Mar 2009, 05:08 PM
Hey all,

I have an MVC app that lets the user use the RadDate and RadTime pickers to choose a date and time for an event (separate inputs).  I read the documentation on how to extract the value... but having some problems when the page is submitted and there are errors.  Namely I want to:  A. Put the value back into the field from ViewData, B. Have a red border show up if the date is invalid (e.g. in the past, or is missing, etc.).

When I try to do a simple <% if (ViewData["regform.Birthdate"]) {%>  etc. it says "Code blocks are not supported in this context".

Anyone able to help me figure out whats going on with this?

Thanks,
Robin

3 Answers, 1 is accepted

Sort by
0
Cole
Top achievements
Rank 1
answered on 04 Mar 2009, 03:40 PM
Specifically...

1. How do you set a value for RadDatePicker/RadTimePicker when running in ASP MVC?

2. How would you set the border for RadDatePicker/RadTimePicker when running in ASP MVC?

I am sure the two are the same approach... just not sure what iit is.

Any help would be appreciated.

Thanks,
Rob
0
Cole
Top achievements
Rank 1
answered on 04 Mar 2009, 04:42 PM
I found a solution... but not sure if it's the best approach.

1. You have to do lots of testing for DateTime being of year 0001 when you extract the datetime to detect a null value.  Handle accordingly in your Controller.

2, Create a code block ABOVE (did not work below) the elements in the page you wish to set value for and do manual insertion from ViewData (which was set in Controller action) to set the value

3. I found that you have to set Selected date on BOTH the picker AND the DateInputField of the picker.  If you don't the value is lost during the next post. 

4. To set error border, just set flag in the ViewData and check that in the same code block as #2 above.  Then do a MyDatePicker.DateInput.BorderColor = System.Drawing.Color.Red; (e.g.).

Hope this helps, 
Can a dev please comment on if there is a more efficient or robust way to do this?  It seems like a lot of hacking for what should be an easy task.

As a suggestion... maybe create a "simple" way to bind the picker and button to an existing text field?  WIthout having to do the manual coding of onblur, dateselection changed etc.  When you have several pickers on your screen it can be a bit annoying to have to do the manual javascript coding for every one etc.

HTH,
Rob
0
gyelle
Top achievements
Rank 1
answered on 04 Mar 2009, 08:47 PM
thanks, was having the same problem :)
Tags
UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Cole
Top achievements
Rank 1
Answers by
Cole
Top achievements
Rank 1
gyelle
Top achievements
Rank 1
Share this question
or