Last post Jun 20, 2011 03:17 AM by princeG
Jun 17, 2011 04:43 PM|1970us|LINK
I have a simple page Default.aspx which has one asp:Literal control named
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplicationTest.Default" culture="auto" meta:resourcekey="PageResource1" uiculture="auto" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<form id="form1" runat="server">
<asp:Literal ID="Literal1" runat="server" Text="Hello" meta:resourcekey="Literal1Resource"></asp:Literal>
I have 3 resx files: 1) Default.aspx.resx file which has Literal1Resource.Text = Hello. 2) Default.aspx.en.resx file which has Literal1Resource.Text = enHello. 3) Default.aspx.fr.resx file which has Literal1Resource.Text = frHello.
In the Default.aspx.cs I override the InitializeCulture method to use the culture stored in the session. If there is no culture stored in session then use en-US as default:
protected override void InitializeCulture()
string culture = null;
culture = (string)Session["culture"];
culture = culture == null ? "en-Us" : culture;
this.Culture = culture;
this.UICulture = culture;
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
To test it I set the session value in Global.asax.cs file in Session_Start method. It is working perfect. If I set Session["culture"] = "en-US"; then the page will show
enHello. If I set Session["culture"] = "fr-FR"; then the page will show
I feel I dont need the Default.aspx.resx file as I will always use Default.aspx.en.resx or Default.aspx.fr.resx files. So I deleted the Default.aspx.resx file. But now it is not working.
It shows Hello when I set Session["culture"] = "en-US"; or Session["culture"] = "fr-FR";
Why it is happening like this? Why I need Default.aspx.resx file when I am not going to use it?
Jun 18, 2011 05:46 PM|Stoian Bucovich|LINK
Well basicaly the default resource file is used to fills up string resources to pages where you haven't set culture globalization or localization.
Hope it helps.
Please, don't forget to mark as "Answered" if it helps. Thanks.
Jun 20, 2011 03:17 AM|princeG|LINK
This is general feature of localization. when you design a applicaton with multilingual, you need to create all resource file enclude defualt file
like Default.aspx.resx, Default.aspx.en-us etc.
if you want to use English is your default language then create default.aspx.resx with english language. without general file resouce will not work.