locked
How to localize Eval data in ASP.NET 2.0? RRS feed

  • Question

  • User-2016200658 posted

    I have a blog written in foreign language. It's maximum two pages out of a 30+pages application. In web.config the culture is set to "neutral". The sitemap and the content display foreign language perfectly fine even without specify culture. BUT, when I use Eval to retrieve the data from database, it's a mess. I tried 4 different ways and none of these work:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

    1) specify culture="zh-CN" at the page top<o:p></o:p>

    2) in Page_Load add System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CreateSpecificCulture("zh-CN");<o:p></o:p>

    3) in Page_Load add <o:p></o:p>

            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("zh-CN");<o:p></o:p>

            Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN");<o:p></o:p>

    4) Specify <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> in the header section<o:p></o:p>

    <o:p> </o:p>

    My code to retrieve data Eval("Title").ToString() for the title and (Eval("Text").ToString()).Replace("\n", "<br />") for the content.<o:p></o:p>

    someone I found in google suggests that data Eval("Title").ToString(System.Globalization.CultureInfo.CreateSpecificCulture("zh-CN")) but obvously won't work.<o:p></o:p>

    <o:p> </o:p>

    Live example at http://www.edream.org/blogcn.aspx you can see the sitemap and the side bar title works well. Only the data from DB mis-display. there is nothing wrong with the data, I have an ASP page using the same data and it works perfectly fine.<o:p></o:p>

    <o:p> </o:p>

    This drives me nuts. Any help is appreciated!

    Wednesday, February 1, 2006 9:09 AM

All replies

  • User1183903743 posted

    Sue,

    What is the client broswer encoding you are viewing this with?

    First, try changing it to Chinese Simplified.

    View|Encoding|More|Chinese Simplified

    I don't know any Chinese to tell if the output is meaningful, but the characters surely look Chinese. If that turns out to be the fix, you might consider changing the encoding to utf-8 for the document and when you update the db.

    Also what is the db data type of the column Text? It should be nvarchar. If sql2005 it should probably be nvarchar(max).

    BTW, is this blog a sandbox or production? You might want to disable custom errors for a production site.

    Why are you casting the master page?  (line 15 of Resume.aspx.cs)

    HTH

    Friday, February 3, 2006 9:12 AM
  • User-2016200658 posted

    Thanks for reply.

    I did everything you said before I posted it here. I am quite familiar with encoding, but this time seems different. I have an ASP.NET 2.0 page blog, Chinese charactor display correctly anywhere inside this page, but NOT the article from database. There is a "Printer friendly" pop up windows cast from ASP page (I haven't yet finish convert the blog from asp to asp.net 2.0), the chinese charater display fine. So I narrow down the problem is not culture setting globalize or local page, neither the database, it is the way retrive article from database using asp.net 2.0.

    The web site was sufferred little technical difficulties at the time your visited. probably last for 10 minutes. Ever since I use dynamic title I got this error message from time to time. I will use lower case for all the pages see if the problem can be solved.

    I modifiy the web site directly from the server at day time so the custom error was on.

    Sue

    Friday, February 3, 2006 9:44 AM
  • User-135515725 posted

    Hi, using the Page_Load event is WAY too late in the event lifecycle to be setting the Culture.  You still need to set the culture manually if you haven't specified it in the @Page or WebConfig, however, you need to use the InitializeCulture() event which is new to .NET 2.0.

    Try this in your Page, I haven't tested it yet but it should give you a start:


    protected override void InitializeCulture() {
                // base.InitializeCulture();
                System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(Session["culture"]);
                Page.Culture = culture;
                System.Threading.Thread.CurrentThread.CurrentCulture = culture;
            }

    Thursday, December 6, 2007 7:14 AM