将多语言设置为一个小型网站

时间:2017-03-20 07:15:59

标签: c#

我正在将set multilang设置为一个小型网站,但我在母版页面有问题,母版页有多个下拉列表..

我的条件是:

  1. 如果我在每个cs页面设置下拉提醒的语言
  2. 在cs页面中,如果我更改语言,lang应该更改,在我的代码page_load函数中有提示下拉列表。
  3. 但我的实际问题是:
    如果我使用lang选择登录,则会打开一个带有下拉列表提醒的cs页面。如果我在该页面中更改lang,则lang现在不会更改,再次选择相同的lang

    这是我的代码,请帮助

    country_master.cs

    protected void Page_Load(object sender, EventArgs e)
    {            
        DropDownList _navigationmenu1 = (DropDownList)Master.FindControl("DrpLangSelector1");
        Session["Lang"] = _navigationmenu1.SelectedValue;
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
    
        //checked sessionexists or not
        if (Session["UserName"] == null || Session["AccessLevel"] == null)
        {
            Response.Redirect("CEFA_Login.aspx?sessionExpired=true", true);
        }
    
        // Set Menu Options
        Menu _navigationmenu = (Menu)Master.FindControl("NavigationMenu");
        Label lblUserNameRole = (Label)Master.FindControl("lblUserNameRole");
        objCommonFunctions.SetMenu(_navigationmenu, lblUserNameRole, Session["UserName"].ToString(), Session["AccessLevel"].ToString(), (bool)Session["isCEFALaunched"], (bool)Session["IsPartTypeAdmin"]);
        //gvCountry.HeaderRow.FindControl("Label1").
    
        if (!IsPostBack)
        {
            //DropDownList _navigationmenu1 = (DropDownList)Master.FindControl("DrpLangSelector1");
            //Session["Lang"] = _navigationmenu1.SelectedValue;
            _navigationmenu.Visible = true;
    
            this.GetCountryData();
        }
    
        ScriptManager scriptmngr = (ScriptManager)Master.FindControl("ScriptManger1");
        scriptmngr.RegisterPostBackControl(btnSubmitCountry);
        scriptmngr.RegisterPostBackControl(btnUpdate);
        Page.Form.Attributes.Add("enctype", "multipart/form-data");
    
        try
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["Lang"].ToString());
            res_man = new ResourceManager("CEFA.App_GlobalResources.CEFA", Assembly.GetExecutingAssembly());
            cul = Thread.CurrentThread.CurrentCulture;
            contryinfobig1.Text = res_man.GetString("CountryInformation", cul);
            countryinfobig.Text = res_man.GetString("CountryInformation", cul);
            lblCountry.Text = res_man.GetString("Country", cul);
            lblCurrencyCode.Text = res_man.GetString("CurrencyCode", cul);
            lblIsCEFALaunched.Text = res_man.GetString("IsCEFALaunched", cul);
            btnSubmitCountry.Text = res_man.GetString("Submit", cul);
            btnClearCountry.Text = res_man.GetString("Clear", cul);
            lblcountrylist.Text = res_man.GetString("CountryList", cul);
            lblMandatory.Text = res_man.GetString("IndicatesMandatoryInputValue", cul);
            //Label4.Text = res_man.GetString("IndicatesMandatoryInputValue", cul);
    
            gvCountry.HeaderRow.Cells[1].Text = res_man.GetString("Country1", cul);
            gvCountry.HeaderRow.Cells[2].Text = res_man.GetString("CurrencyCode1", cul);
            gvCountry.HeaderRow.Cells[3].Text = res_man.GetString("IsCEFALaunched1", cul);
            gvCountry.PagerSettings.FirstPageText = res_man.GetString("First", cul);
            gvCountry.PagerSettings.LastPageText = res_man.GetString("Last", cul);
            gvCountry.PagerSettings.NextPageText = res_man.GetString("Next", cul);
            gvCountry.PagerSettings.PreviousPageText = res_man.GetString("Prev", cul);
    
            // gvCountry.Columns[4].Text=res_man.GetString("IsCEFALaunched", cul);
            //((Label)gvCountry.Columns[4].Text = res_man.GetString("IsCEFALaunched", cul);
        }
        catch (Exception s)
        {
            Console.WriteLine(s);
        }
    
    }
    

    的Site.Master:

        protected void Page_Load(object sender, EventArgs e)
        {
             DrpLangSelector1.SelectedValue=Session["Lang"].ToString();
            // NavigationMenu.me
    
            //string x = NavigationMenu.SelectedValue.ToString();
    
            if (ConfigurationManager.AppSettings["RunEnvironment"] != "Production")
            {
                lblHeader.Text = "COMPONENT EVALUATION FAILURE ANALYSIS - " + ConfigurationManager.AppSettings["RunEnvironment"];
                lblHeader.ForeColor = System.Drawing.Color.MediumVioletRed;
            }
            int id1 = Session["AccessLevelId"].ToInt32();
             }
        }
        protected void Page_Init(object sender, EventArgs e)
        {
    
        }
        protected void NavigationMenu_MenuItemClick(object sender, MenuEventArgs e)
        {
            if (NavigationMenu.SelectedValue.ToString() == res_man.GetString("Logout", cul))
            {
                //Session["UserName"] = "";
                //Session["AccessLevel"] = "";
                Response.Redirect("CEFA_Login.aspx", false);
            }
    
            // MODIFICATION STARTS: To change all Master screen names in Menu, screen title and every where else to "Information"  | Modified By: Mithun Chikhalikar | Date: June 10, 2014
            //if (NavigationMenu.SelectedValue.ToString() == "Masters")
            if (NavigationMenu.SelectedValue.ToString() == res_man.GetString("Information", cul))
            // MODIFICATION ENDS: To change all Master screen names in Menu, screen title and every where else to "Information"  | Modified By: Mithun Chikhalikar | Date: June 10, 2014
            {
                DrpLangSelector1.SelectedValue = Session["Lang"].ToString();
                Response.Redirect("blank.aspx", false);
            }
            if (NavigationMenu.SelectedValue.ToString() == res_man.GetString("Reports", cul))
            {
                Response.Redirect("blank.aspx", false);
            }         
        }
    
        protected void upOnload(object sender, EventArgs e)
        {            
            Page.Header.Controls.Add(new LiteralControl("<script type='text/javascript' src='" + Page.ResolveUrl("Scripts/imagepanner.js") + "'></script>"));           
        }
    
        protected void DrpLangSelector1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["Lang"] = DrpLangSelector1.SelectedValue;
            Session["Langindex"] = DrpLangSelector1.SelectedIndex;
            // string x = NavigationMenu.SelectedValue.ToString();
            int id1 = Session["AccessLevelId"].ToInt32();
            if (Session["Lang"] != null)
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["Lang"].ToString());
                res_man = new ResourceManager("CEFA.App_GlobalResources.CEFA", Assembly.GetExecutingAssembly());
                cul = Thread.CurrentThread.CurrentCulture;
                lblHeader.Text = res_man.GetString("COMPONENTEVALUATIONFAILUREANALYSISDevelopment", cul);
                int id = Session["Accessid2"].ToInt32();
           }
         } 
      }
    }
    

0 个答案:

没有答案