To set the culture and UI culture for an ASP.NET Web page programmatically override the InitializeCulture method for the page
.
protected override void InitializeCulture()
{
if (Session["UserLanguage"] != null)
{
String selectedLanguage = Session["UserLanguage"].ToString();
UICulture = selectedLanguage ;
Culture = selectedLanguage ;
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new
CultureInfo(selectedLanguage);
}
base.InitializeCulture();
}
source:-Set the Culture and UI Culture for ASP.NET Web Page
To fix this, you could create a BasePage that all your specific pages inherit:
- Create a new Class (not Webform), call it BasePage, or whatever you want.
- Make it inherit System.Web.UI.Page.
- Make all your other pages inherit the BasePage.
Here's an example:
public class BasePage : System.Web.UI.Page
{
protected override void InitializeCulture()
{
//Do the logic you want for all pages that inherit the BasePage.
}
}
And the specific pages should look something like this:
public partial class _Default : BasePage //Instead of it System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Your logic.
}
//Your logic.
}