locked
how to get current Language or culture from previous page? RRS feed

  • Question

  • User-1933799866 posted

    Hi,

    i create a simple webpage to test the Localization. i create two pages.

    Default.aspx & Welcome.aspx

    i use two languages ENglish & FRench. i already created Localized folder & .RESX of both.

    but i can change only current page languages. using UIculture.

    but i click on the link for Welcome.aspx.... it still show me ENglish, not showing french. Language conversation only going on Default.aspx page.

    here is my Coding:-

    for DEFAULT.ASPX:

    <form id="form1" runat="server">
    <div>

    <asp:Label ID="wlcm_msg" runat="server" meta:resourcekey="wlcm_msgResource1"></asp:Label>
    <br />
    <br />
    <asp:Label ID="country_name" runat="server"
    meta:resourcekey="country_nameResource1"></asp:Label>
    <br />
    <br />
    <asp:LinkButton ID="page_2" runat="server" meta:resourcekey="page_2Resource1"
    onclick="page_2_Click" PostBackUrl="~/Welcome.aspx"></asp:LinkButton>

    <br />
    <br />
    <asp:Label ID="langBT" runat="server"></asp:Label>
    <br />
    <asp:LinkButton ID="fr_lang" runat="server"
    PostBackUrl="~/Default.aspx?Language=fr-FR">France</asp:LinkButton>
     
    <asp:LinkButton ID="en_lang" runat="server"
    PostBackUrl="~/Default.aspx?Language=en-US">English</asp:LinkButton>

    </div>
    </form>


    and for DEFAULT.ASPX.CS in C# coding:


    public partial class _Default : System.Web.UI.Page 
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected override void InitializeCulture()
    {

    if (Request["Language"] != null)
    {
    Thread.CurrentThread.CurrentCulture = new CultureInfo(Request["Language"].ToString());
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(Request["Language"].ToString());
    }
    base.InitializeCulture();
    }
    }


    HERE is the coding of WELCOME.ASPX page:

    <form id="form1" runat="server">
        <div>
        
            <asp:Label ID="welcome_page" runat="server" 
                meta:resourcekey="welcome_pageResource1"></asp:Label>
            <br />
            <asp:Image ID="country_flag" runat="server" Height="154px" Width="179px" 
                meta:resourcekey="country_flagResource1" />
            <br />
            <br />
            <asp:LinkButton ID="back_bt" runat="server" meta:resourcekey="back_btResource1" 
                PostBackUrl="~/Default.aspx"></asp:LinkButton>
        
        </div>
        </form>

    Now what i have to write in welcome's CS file???


    Monday, February 14, 2011 5:50 AM

Answers

  • User191633014 posted

    you can use session to pass the selected value to 2 page:

        protected override void InitializeCulture()
        {
            if (Request["Language"] != null)
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo(Request["Language"].ToString());
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(Request["Language"].ToString());
                Session["Language"] = Request["Language"].ToString();
            }
            else if(Session["Language"]!=null)
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["Language"].ToString());
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(Session["Language"].ToString());
            }
    
            base.InitializeCulture();
        }


    you should implement  InitializeCulture in second page too.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 14, 2011 8:06 AM