locked
Problems with InitializeCulture() RRS feed

  • Question

  • User1247667309 posted

    Im trying to set upp localization with resource files for different languages. After reading tutorial i think i understand how it is done.

    But when i try to use the InitilializeCulture i get an error!

    Error 5 'FrontEndNavigator.InitializeCulture()': no suitable method found to override 21 E:\Dokuments\Programming Experiments\Finska Institutet\ShortFrontEndNavigator.master.cs 29 E:\...\Finska Institutet\


    "FrontEndNavigator.InitializeCulture()': no suitable method found to override"



    Here is part of my page:

    public partial class FrontEndNavigator : System.Web.UI.MasterPage
    {
    
        protected override void InitializeCulture()
        { 
               if (Session["Language"] == null || Session["Language"] == "sve")
            {
                Session["Language"] = "sve";
                Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE");
            }
            else 
            {
    
                Session["Language"] = "fi";
                   Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fi");
                   Thread.CurrentThread.CurrentUICulture = new CultureInfo("fi-FI");
            }
        
        }
    
        
        
        protected void Page_Load(object sender, EventArgs e)
        {
    
     
         
            if (IsPostBack == false)
            {
              
            RefreshLinksRepeater();
            }
    
         
    
        }



    Thanks for your time and let me know if you need some other info!

    Lautaro.

     

    Wednesday, August 25, 2010 7:19 AM

Answers

  • User-1200560727 posted

    This post will helpful to you: http://forums.asp.net/p/1333543/2681302.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 26, 2010 3:05 AM
  • User-25924017 posted

    As for making the master page inherit from a page class, i cant see how that can work. Wont my master pages loose their master page functionality then? Sounds dangerous!

    you should not do that and there is no need.

    You need only content page(s) class to be inherited from a base class and not master.

    You simply need to add a class inherited from Page class something like this, I name it DefaultBaseClass:


        public class DefaultBaseClass : System.Web.UI.Page
        {
            public DefaultBaseClass()
            {
                //
                // TODO: Add constructor logic here
                //
    
            }
    
            protected override void InitializeCulture()
            {
                String selectedLanguage = "en-US";
    
                if (!(Session["Language"] == null))
                {
                    selectedLanguage = Session["Language"].ToString();
                }
                if (!string.IsNullOrEmpty(selectedLanguage))
                {
                    UICulture = selectedLanguage;
                    Culture = selectedLanguage;
    
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage);
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);
    
                }
                base.InitializeCulture();
            }
    
    
        }
    


    now create your content pages derived from above DefaultBaseClass:


    public partial class DefaultTemp : DefaultBaseClass
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 26, 2010 5:47 AM

All replies

  • User-126244515 posted

    This might give you an idea of why this isn't working and how to solve it, http://forums.asp.net/t/955888.aspx.

    Wednesday, August 25, 2010 9:30 AM
  • User-1200560727 posted

    This post will helpful to you: http://forums.asp.net/p/1333543/2681302.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 26, 2010 3:05 AM
  • User1247667309 posted

    Thanks for your time guys!

    It didnt work with the solution to uncheck the checkbox on build webpage. Still i didnt like that solution cause im not aware what consequences it could have.

    Itried to rename the pages, so that no 2 pages inherited fromthe same class but that didnt work out either. Not sure i really understood that solution.

    As for making the master page inherit from a page class, i cant see how that can work. Wont my master pages loose their master page functionality then? Sounds dangerous!

    I tried to use the Onpreinit() but it seems master pages dont have that either.

    What i think is very weird is that all the ASPnet tutorials i have seen dont say anything about the problems with initializeculture on master pages, but they use master pages in their example. 

    Im still on zero, can you provide anymore help?


    Thursday, August 26, 2010 4:38 AM
  • User-1200560727 posted

    The MasterPage class is used as a template for your web application. When an HTTP request is made for this web page at run time, the master page and content pages are combined into a single class with the same name as the content pages. The resulting compiled, merged class derives from the Page class.This means that you cannot override the InitializeCulture method in the MasterPage page class. You override this method in your aspx page.

    I hope this will solve your problem.

    Thursday, August 26, 2010 5:32 AM
  • User-25924017 posted

    As for making the master page inherit from a page class, i cant see how that can work. Wont my master pages loose their master page functionality then? Sounds dangerous!

    you should not do that and there is no need.

    You need only content page(s) class to be inherited from a base class and not master.

    You simply need to add a class inherited from Page class something like this, I name it DefaultBaseClass:


        public class DefaultBaseClass : System.Web.UI.Page
        {
            public DefaultBaseClass()
            {
                //
                // TODO: Add constructor logic here
                //
    
            }
    
            protected override void InitializeCulture()
            {
                String selectedLanguage = "en-US";
    
                if (!(Session["Language"] == null))
                {
                    selectedLanguage = Session["Language"].ToString();
                }
                if (!string.IsNullOrEmpty(selectedLanguage))
                {
                    UICulture = selectedLanguage;
                    Culture = selectedLanguage;
    
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage);
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);
    
                }
                base.InitializeCulture();
            }
    
    
        }
    


    now create your content pages derived from above DefaultBaseClass:


    public partial class DefaultTemp : DefaultBaseClass
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 26, 2010 5:47 AM
  • User-1636183269 posted

    I agree with SSA.

    create common base page, go through below forum

    http://forums.asp.net/t/1514920.aspx

    Thursday, August 26, 2010 10:03 AM
  • User-88139571 posted

    The culture has a great impact on working and developing a multilingual sites fordifferent target makes a revolution in the working wnvironment but the feasibility has to be checked

    Thursday, September 2, 2010 1:16 AM