O'Reilly logo

Professional ASP.NET 3.5 AJAX by Matt Gibbs, Dan Wahlin, Bill Evjen, Dave Reed

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

13.4. Client-Side Culture Details

When working with culture on the client side, the culture that is used is the culture that is defined on the server. Therefore, if you have the culture set to en-US on your server, this is the default that is utilized on the client-side operations as well. Consider the example presented in Listing 13-8.

Example 13-8. Viewing dates with a culture setting as set on the server
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Globalization"%>

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("Date from the server before setting culture: " +
           DateTime.Now + "<br />");
        System.Threading.Thread.CurrentThread.CurrentCulture =
           new CultureInfo("ru-RU");
        Response.Write("Date from the server after setting culture: " +
           DateTime.Now);
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">

        function pageLoad() {

            var date = new Date();
            $get('Label1').innerHTML = "Date after setting culture on the client: "
               + date.localeFormat("D");
            alert(String.localeFormat("{0:dddd, dd MMMM yyyy hh:mm:ss tt}",
               new Date()));

      }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server"
         EnableScriptGlobalization="true" />
        <span id="Label1"></span>
    </div>
    </form>
</body>
</html>

First off, to work with setting the culture on the server, you need to import the System.Globalization namespace. The first thing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required