Reputation: 333
I have a web form page and want to set language from code behide using resource files and the meta in label control. Parameter is from somewhere else.
<asp:Label ID="lblTitle" runat="server" Text="" meta:resourcekey="lblTitle"></asp:Label>
However, in this way (meta), it will read the preferred language from browser and set the cultural automatically. For example, if the perfered language from broswer is en-AU, then it will starting reading info from my recourse file xxxx.aspx.en-AU.resx. I don't want it that way as I want to control everything manually.I have to explicitly handle this from code behind.
Can I turn off this auto-binding from the browser?
Upvotes: 0
Views: 254
Reputation: 241
In web.config, you can force a specific culture for your application. For en-US
, you can use this.
Web.config
<system.web>
<globalization culture="en" uiCulture="en-US"/>
...
</system.web>
In your code-behind, you can then override at will using:
var lang = "en-AU";
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
Upvotes: 2