Saturday, 9 July 2011

It's Friday I'm In Love

I am building a new service, which is going to be Events.
While doing so, I came across some interesting question: how to get the client culture settings?
Because I want to know which day is the first day of the week in my user's world.

Turns out all you have to do is to setup your page so that it gets these settings automatically,


<%@ Page Title="Events" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Events.aspx.cs" Inherits="romama.Calendar.Events" ClientIDMode="Predictable"
    UICulture="auto" Culture="auto" %>

and attaches them to the current thread.

So I set up my calendar so that my first day of week is Tuesday (which is kind of true).


But still, my thread current culture (Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek) says it is Monday.

Turns out you don't get the complete culture info from the client, which actually makes sense. Instead, you get the preferred language chosen in the user's browser settings, which is used to determine the culture settings.

Change it to en-US and you'll get Sunday.

Yes, you can see the skeleton of calendar on the background.

No comments:

Post a Comment