javascript - How to integrate datetimepicker with ASP.NET localisation -
i'm using trent richardson's datetimepicker extension jquery, obtained via nuget: http://trentrichardson.com/examples/timepicker/
trent's documentation says can create localised datetimepicker this:
$('#basic_example_4').timepicker( $.timepicker.regional['es'] );
i'm attaching datetimepicker asp.net textbox setting cssclass property on textbox, , having javascript attach datetimepicker selecting on css class:
<script type="text/javascript"> $(document).ready(function () { $('.calendarstartdatetime').datetimepicker({ dateformat: 'yy-mm-dd', timeformat: 'hh:mm tt', controltype: 'select', oneline: true }); }); </script> ... <asp:textbox id="startdatetime" runat="server" cssclass="calendarstartdatetime" meta:resourcekey="startdatetimeresource1"></asp:textbox>
my asp.net page declaration sets culture="auto"
, uiculture="auto"
asp.net elements pick culture settings browser settings (and can use asp.net resources localise text).
i datetimepicker automatically apply localisation based on browser settings, consistently how server-side components being localised. how achieve this? need insert asp.net tag javascript, like:
<script type="text/javascript"> $(document).ready(function () { $('.calendarstartdatetime').datetimepicker({ $.timepicker.regional[<% magic happens here %>], controltype: 'select', oneline: true }); }); </script>
or should browser culture detected in pure javascript?
edit: based on @smirnov's answer, final code timepicker was:
<script type="text/javascript"> $(document).ready(function () { $('.calendarstartdatetime').datetimepicker( $.extend( {}, $.datepicker.regional['<%= system.globalization.cultureinfo.currentculture.twoletterisolanguagename %>'], $.timepicker.regional['<%= system.globalization.cultureinfo.currentculture.twoletterisolanguagename %>'], { dateformat: 'yy-mm-dd', timeformat: '<%= system.globalization.cultureinfo.currentculture.datetimeformat.shorttimepattern %>', controltype: 'select', oneline: true } ) ) }); </script>
this code correctly merges regionalisation settings jquery's built-in datepicker, trent richardson's timepicker properties, , custom settings.
use cultureinfo.currentculture.twoletterisolanguagename
as timepicker seems use country code value regional, try
... $.timepicker.regional['<%=system.globalization.cultureinfo.currentculture.twoletterisolanguagename%>'], ...
Comments
Post a Comment