Good day! I do a programmatic language change as described here . Why created a separate page for changing the language, here's the code:

<%@ Page Title="" Language="VB" AutoEventWireup="false" CodeFile="ChangeLanguage.aspx.vb" Inherits="Default2" %> <%@ Import Namespace="System.Threading" %> <%@ Import Namespace="System.Globalization" %> <script runat="server"> Protected Overrides Sub InitializeCulture() If Request.Form("ListBox1") IsNot Nothing Then Dim selectedLanguage As String = _ Request.Form("ListBox1") UICulture = Request.Form("ListBox1") Culture = Request.Form("ListBox1") System.Threading.Thread.CurrentThread.CurrentCulture = _ CultureInfo.CreateSpecificCulture(selectedLanguage) System.Threading.Thread.CurrentThread.CurrentUICulture = New _ CultureInfo(selectedLanguage) End If MyBase.InitializeCulture() End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ListBox ID="ListBox1" runat="server"> <asp:ListItem Value="en" Selected="True">English</asp:ListItem> <asp:ListItem Value="ru">Русский</asp:ListItem> </asp:ListBox><br /> <asp:Button ID="Button1" runat="server" Text="Set Language" meta:resourcekey="Button1" /> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/default.aspx">HyperLink</asp:HyperLink> <br /> </div> </form> </body> </html> 

On this page, the language changes normally, but after switching to any other page, the language is reset to "default". What am I doing wrong, how to implement a language change for all pages at once?
.NET 4.0.
Web Developer 2010 Express.

    1 answer 1

    It is necessary to redefine InitializeCulture on each page, or make an interlayer as a base page and inherit all the rest from it.

    • Please in more detail. If you override for each page, then where and how to store the language settings? Is System.Threading.Thread.CurrentThread.CurrentCulture not for all pages of the application? Layer is the master page? - Ildar
    • On the master page unfortunately there is no this method for setting culture. You need to create a class, a successor from Page (let's say BasePage), override this method in it, and all other pages like login, restructuring, etc., inherit from this BasePage. You can store the language for example in a session. As for how: when a user chooses a language, put the selected language and everything into the session, and in the redefined InitializeCulture method, pull the desired culture not from the ListBox, as you have now, but from the session. - wind
    • Thank you for what you need. Do not hover on the material about working with sessions? - Ildar
    • There is soooo much material in the net, as in every book on ac - I am just confused about what to give =) google.com.ua/… - wind
    • In the simple case, it all boils down to something like this: Session ("MyCulture") = "RU-ru" // put the necessary string into the session String c = Session (). ToString () // get the string from the session, just another check On zero it is necessary before. - wind