locked
Master Page Localization RRS feed

  • Question

  • User1389224148 posted

    I have a website that I need to be able to view in 2 languages. My issue is I have a dropdown box in the master page whose values I don't know how to get. I have a base page,default page & the master page.

    Code (Base Page)

    Protected Overrides Sub InitializeCulture()
            Dim lang As String = Request("ddlLanguage")
    
            If lang IsNot Nothing Or lang <> "" Then
                Thread.CurrentThread.CurrentUICulture = New CultureInfo(lang)
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang)
            End If
            MyBase.InitializeCulture()
        End Sub

    Don't know how to get the selected value from the master page.

    Can anyone guide me in the right direction.

    Thanks

    Tuesday, October 4, 2011 4:21 PM

Answers

  • User1389224148 posted

    This is what worked for me:

    Master Page:

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
             If Not Page.IsPostBack Then
                ddlLanguage.SelectedValue = Session("MyCulture")
            End If
            
        End Sub
    
     Private Sub ddlLanguage_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlLanguage.SelectedIndexChanged
            If Not Session("MyCulture") = ddlLanguage.SelectedValue Then
                Session("MyCulture") = ddlLanguage.SelectedValue
    
            End If
    
          
                Response.Redirect(Request.Url.ToString())
    
    
    
        End Sub
    
    App_Code/Base_Page.vb:
    Protected Overrides Sub InitializeCulture()
    
    
            Dim language As String = Session("MyCulture")
    
            If language IsNot Nothing Or language <> "" Then
    
                Thread.CurrentThread.CurrentUICulture = New CultureInfo(Session("MyCulture").ToString)
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Session("MyCulture").ToString)
            End If
    
            MyBase.InitializeCulture()
    
    
    
        End Sub
    
    Default.aspx.vb change to Public Class _Default
        Inherits BasePage_Localization
    
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 18, 2011 3:37 PM

All replies

  • User900039493 posted

    Hello reeba2011,

    Maybe this code can help.

       Protected Overrides Sub InitializeCulture()
            Dim ddl As DropDownList = DirectCast(Master.FindControl("ddlLanguage"), DropDownList)
            Dim lang As String = Request.Form(ddl.UniqueID)
    
            If lang IsNot Nothing Or lang <> "" Then
                Thread.CurrentThread.CurrentUICulture = New CultureInfo(lang)
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang)
            End If
            MyBase.InitializeCulture()
        End Sub

    Regards

    Florian P

    Thursday, October 6, 2011 4:56 AM
  • User1389224148 posted

    This is what worked for me:

    Master Page:

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
             If Not Page.IsPostBack Then
                ddlLanguage.SelectedValue = Session("MyCulture")
            End If
            
        End Sub
    
     Private Sub ddlLanguage_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlLanguage.SelectedIndexChanged
            If Not Session("MyCulture") = ddlLanguage.SelectedValue Then
                Session("MyCulture") = ddlLanguage.SelectedValue
    
            End If
    
          
                Response.Redirect(Request.Url.ToString())
    
    
    
        End Sub
    
    App_Code/Base_Page.vb:
    Protected Overrides Sub InitializeCulture()
    
    
            Dim language As String = Session("MyCulture")
    
            If language IsNot Nothing Or language <> "" Then
    
                Thread.CurrentThread.CurrentUICulture = New CultureInfo(Session("MyCulture").ToString)
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Session("MyCulture").ToString)
            End If
    
            MyBase.InitializeCulture()
    
    
    
        End Sub
    
    Default.aspx.vb change to Public Class _Default
        Inherits BasePage_Localization
    
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 18, 2011 3:37 PM
  • User1784660007 posted

    I am also getting the same problem in C# code i have tried your code 

    on master page :

    protected void Page_Load(object sender, EventArgs e)
    {
    DropDownList1.SelectedValue = Session["MyCulture"].ToString();
    }

    and on the child page i have written code:

    protected override void InitializeCulture()
    {

    string language = Session["MyCulture"].ToString();
    if (language != null || language != "")
    {
    Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Session["MyCulture"].ToString());
    Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(Session["MyCulture"].ToString());
    }
    base.InitializeCulture();

    }

    but its not working 

    help me 

    thanks 

    Tuesday, December 3, 2013 7:33 AM