locked
How should I implement the localization method with master page? RRS feed

  • Question

  • User-718065650 posted

    Hi Expert,

    I want to put an AutoPostBack dropdownlist at the top of master page to choose the language the user wants. I did the same way as what the video tells me: How Do I: Create a Multi-Lingual Site with Localization? But when I browse the webpage, it has error!! Here is the code in master.aspx.vb

    Protected Sub InitializeCulture()

    Dim lang As String = Request("Language")

    If lang IsNot Nothing Or lang <> "" Then

    Thread.CurrentThread.CurrentUICulture = New CultureInfo(lang)

    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang)

    End If

    End Sub

     master.aspx source code:

    <td style="background- center; background-image: url(Images/logo-flextronics.gif);

    background-repeat: no-repeat; height: 60px; background-color: #002d5a; font-size: 16pt; color: gold; font-family: 'Arial Rounded MT Bold'; text-align: right; vertical-align: bottom;">

    <asp:Label ID="Label1" runat="server" Style="" Text="<%$ Resources:Resource, Welcome %>"></asp:Label>

    <asp:DropDownList ID="Language" runat="server" AutoPostBack="True" Style="">

    <asp:ListItem Value="en-US">English</asp:ListItem>

    <asp:ListItem Value="zh-hk">Chinese</asp:ListItem>

    </asp:DropDownList></td>

    Wednesday, August 9, 2006 5:53 PM

All replies

  • User-1936818034 posted

    Hi~ Notice the MasterPage is derived form UserControl but not Page class, so unfortunately there is no InitializeCulture() for it~ [;)]

    One solution is as blows:

    Let the user choose preferred language from your drop down. Once he chose one, store the value in Cookie or Profile, or any where you want.

    Create a Global.asax, in Application_BeginRequest(), read culture setting from where you stored it, then set Thread.CurrentThread.CurrentUICulture and Thread.CurrentThread.CurrentCulture. This is because BeginRequest is touched off before the MasterPage's lifecycle.

    Additional, after user selected his culture, you should refresh that page to make it work. xD

    There are already some discussion for your issue in This Thread~

     

    Wednesday, August 9, 2006 11:51 PM