Question

here is the my question.I have a master page which contain some flags to set the web page language.

inside the master page I have a user controller which contains menu items. These menu items depend on the flag chose, it change.

when I look at the life cycle of the web application ,first run, mainpage_loader,later run the user control loader,in the end, run the function (flag button function ) defined inside the main page.

but what I need that is get the session value,inside the user control. Depends on the this session value,load the menu depends on language chosen. but in this case I never catch the session value,inside user control as after pass the step masterpage function. how can I solve this problem. thanks.

MY MASTER PAGE

     protected void Page_Load(object sender, EventArgs e)
            {
                if (Session["lang"]==null)
                {
                    Session["lang"] = "m_en";

                }
                else
                {

                }

            }


         [DirectMethod(IDMode = DirectMethodProxyIDMode.None)]
            public void Change_Lang_Event(string lang)
            {    
                CultureInfo ci;

                switch (lang)
                {
                    case "m_tr":
                        ci = new CultureInfo("tr-TR");
                        Session["lang"] = "m_tr";
//problem is here I coulnt reach Language properti
       ((UserControl)Page.Master.FindControl("MyMenu1")).Language = Session["lang"].ToString();


                        break;
                    case "m_en":
                        ci = new CultureInfo("en-US");
                        Session["lang"] = "m_en";



                        break;
                    case "m_ru":
                        ci = new CultureInfo("ru-RU");
                        Session["lang"] = "m_ru";




                    default:
                       ci = new CultureInfo("tr-TR");
                        Session["lang"] = "m_tr";


                        break;
                }

MY USERCONTROL :

 public partial class MyMenu : System.Web.UI.UserControl

{
    static List<Ofis> lst;
    static CultureInfo cim;
    string dilSesion = "";
    private string _languages;

    public string Languages
    {
        get { return _languages; }
        set { _languages = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

       dilSesion =   Session["lang"].ToString();
      X.Msg.Alert("Uyarı", dilSesion).Show();


    }



}

Main aspx;

 <asp:Contentplaceholder id="Contentplaceholder1" runat="server">
            <uc1:MyMenu ID="MyMenu1" runat="server" />
        </asp:Contentplaceholder>
Was it helpful?

Solution

If you define a property in the UserControl i.e.

private string _language;

public string Language
{
    get
    {
        return _language;
    }

    get
    {
        return _language;
    }

}

Then you could set it in the MasterPage code behind:

((UserControl)Page.Master.FindControl('controlID')).Language = Session["lang"].ToString()

Please note the user control will have to be cast to your UserControl class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top