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

RadDatePicker losing format on Postback

1 Answer 164 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Chance
Top achievements
Rank 1
Chance asked on 08 Jun 2016, 03:26 PM

I have the format set to be M/d/yyyy, and it works when selecting a date but if there is any postback on the page it changes for format to use the dashes like M-dd-yyyy.  Any ideas how to fix this?

 

 

<telerik:RadDatePicker ID="radGridDate1" Runat="server" SelectedDate='<%# DateTime.Parse( Eval("Date", "{0:M/dd/yyyy}")) %>' Width="100px" Skin="Bootstrap" >
                                                 <Calendar EnableWeekends="True"  ShowRowHeaders="false" Skin="Bootstrap" > </Calendar>
                                                 <DateInput DateFormat="M/d/yyyy" DisplayDateFormat="M/d/yyyy" LabelWidth="40%">
                                                     <EmptyMessageStyle Resize="None" />
                                                     <ReadOnlyStyle Resize="None" />
                                                     <FocusedStyle Resize="None" />
                                                     <DisabledStyle Resize="None" />
                                                     <InvalidStyle Resize="None" />
                                                     <HoveredStyle Resize="None" />
                                                     <EnabledStyle Resize="None" />
                                                 </DateInput>
                                                 <DatePopupButton HoverImageUrl="" ImageUrl="" />
                                            </telerik:RadDatePicker>

Thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Vasil
Telerik team
answered on 09 Jun 2016, 12:24 PM
Hi Chance,

The slash(/) is special symbol in the date format string, and it is culture dependent:
https://msdn.microsoft.com/en-us/library/8kb3ddd4%28v=vs.110%29.aspx#dateSeparator
It is used as "Date Separator" and will be changed with "-" can be changed "." according to the current culture.

So you should escape it using back slash(\). Like "M\/dd\/yyyy"

See this documentation for further information:
https://msdn.microsoft.com/en-us/library/8kb3ddd4%28v=vs.110%29.aspx

If you are setting the format using C# code you should escape the back slash as well as required in the language syntax.

So the correct code will be:
<telerik:RadDatePicker ID="radGridDate1" Runat="server"
SelectedDate='<%# DateTime.Parse( Eval("Date", "{0:M\\/dd\\/yyyy}")) %>' >
<DateInput DateFormat="M\/d\/yyyy">
</DateInput>
</telerik:RadDatePicker>

Regards,
Vasil
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Calendar
Asked by
Chance
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or