I have a web page (.aspx) which uses a master page and loads a user control (.ascx) within the开发者_JS百科 web page. I am implementing localization on both the page and the user control. however the localization is only working on the user control part but not the .aspx page.
There is a basepage class that all my web pages inherit and within the basepage class I am overriding the InitializeCulture() method and here I set the currentculture and currentuiculture. For test purposes, I have specifically set the culture and currentuiculture to "fr-CA".
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA");
I have the .resx files generated for both the .aspx file and .ascx file for both the default language i.e "English" and "french" using visual studio.
Not sure why the localization is not working on the .aspx file but works fine on the user control.
You could override Page
's OnInit
method and set Page.UICulture
property there.
Also, have you named both your French resources correctly? I would suggest to use "fr" rather than "fr-CA" as soon as you don't use more than one French.
Try the instructions at this page:
http://msdn.microsoft.com/en-us/library/bz9tc508(v=VS.85).aspx
protected override void InitializeCulture()
{
string selectedLangauge = "fr-CA";
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new
CultureInfo(selectedLanguage);
base.InitializeCulture();
}
My guess is that you're not setting the culture early enough, but the user control is working because of catch-up events. ( http://msdn.microsoft.com/en-us/library/ms178472.aspx#catch_up_events_for_added_controls )
精彩评论