Take the 2-minute tour ×

I'm trying to localize an asp.net web application. Consider the following asp.net code. I'm running with CurrentCulture and CurrentUICulture set to German ("DE-DE").

<%= ReportTitles.EndOfDay %>
<asp:Literal ID="litLabel" runat="server" Text="<%$ Resources:ReportTitles, EndOfDay %>"/>

I expect these two lines to yield the same result, but instead I get this:

Auswertungen für den Tagesabschluss
End of Day

In other words, the first syntax <%= ReportTitles.EndOfDay %>successfully retrieves the value from the ReportTitles.de.resx file we're using, but the second syntax <asp:Literal ID="litLabel" runat="server" Text="<%$ Resources:ReportTitles, EndOfDay %>"/> gets the value out of the default US English ReportTitles.resx file.

What's wrong with the 2nd line? Thanks

share|improve this question
Could you provide us with an example how (and when) you set CurrentCulture/CurrentUICulture? –  Simon Svensson Aug 26 '10 at 16:29
It is set in the Page_Load of the master page, and it happens more or less like this... Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("DE-DE"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("DE-DE"); –  Booberry Aug 26 '10 at 18:52
add comment

1 Answer

up vote 2 down vote accepted

Setting culture during Load is somewhere in the middle of the life cycle. This is after the literal control has been created.

Basically, the control tree is created when Page.ProcessRequest calls FrameworkInitialize, which calls __BuildControlTree, a method autogenerated from your code file. It will instantiate a new Literal control, set all properties, and add it to the control tree. It has basically already read from the active ResourceManager. This is before Load, it's even before PreInit. This means that you havn't changed culture yet.

<%= ... %> will be parsed into a call to HtmlTextWriter.Write during render. This is at the end of the life cycle, and it will use the new culture.

The usual place to implement this is either using a HttpModule/HttpHandler or overriding Page.InitializeCulture.

Check out http://ghferr.free.fr/wiki/Articles/images/aspnet_page-control-life-cycle.jpg, a overview worth printing and putting on a wall in your vicinity. ;)

share|improve this answer
Thanks for the info. I overrode the InitializeCulture in our BasePage class and that did the trick. As soon as I have the rep I'll vote you up. :) –  Booberry Aug 26 '10 at 21:23
add comment

Your Answer


