Best Practices
General > Best Practices > Access to Culture on Client Side View modes: 
User avatar
Member - 8/6/2008 11:07:33 AM
Access to Culture on Client Side

I need the culture code (ie- en-US, es-ES, etc) on the client side (Javascript). I know i can use CMS.CMSHelper.CMSContext.CurrentUser.PreferredCultureCode on the server side, but is it easily accessible for use on the Client side? Any suggestions?


User avatar
Kentico Developer
Kentico Developer
kentico_martind - 8/6/2008 2:08:41 PM
RE:Access to Culture on Client Side

You can put some 'literal' control onto the page (if you are using portal engine, you can put it into some user control that you can put on the page using UserControl web part) and into 'Text' property of this literal you can put (e.g. in Page_Load method) HTML tag 'input' of type 'hidden' and into its 'value' attribute insert the culture code.

Please find sample code bellow:
ltlInput = "<input type=\"hidden\" id=\"cultureCode\" name=\"cultureCode\" value=\"" + CMS.CMSHelper.CMSContext.CurrentUser.PreferredCultureCode + "\" />";

Then the culture code will be not visible on the page, but it will be present in the HTML source code of the page, so you will be able to access the value using javascript (e.g. using GetElementByID function).

Best Regards,
Martin Dobsicek