Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
475
WebMenu localization at runtime not working
posted

Hi!

I am using an UltraWebMenu at my site and I allow the users to change the language of the site to their liking by selecting from a dropdownlist of available languages.  The UltraWebMenu is populated by retrieving various information from a database including the localized text for each menu item.  All this information is inserted into a XML file (XmlDocument into a XmlDatasource) and then it is set as the UltraWebMenu datasource and it databinded.  When debugging the code the correct XML datasource is assigned to the menu and  when checking the contents of the UltraWebMenu datasource it contains the correct localized texts, but the localized text is not displayed in the browser, it still shows the previous localization.

Is there a cache the UltraWebMenu is using that is holding tight to the item text or am I missing something.

Here is the menu creation code (the same code is executed when changing the language):

XmlDataSource xmlData = new XmlDataSource();
            xmlData.ID = "xmlDataSourceFIBSMenu";
            XmlDocument xmlDoc = new XmlDocument();
            XmlDeclaration xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
            xmlDoc.AppendChild(xmlDec);

            XmlElement xmlMenu = xmlDoc.CreateElement("Menu");
            List<Role> systems = (List<DTO.Role>)LocalizeRoleList(m.FIBS.GetRolesForEmployeeList(employee.ID, 0));
            systems.Sort(DTO.RoleComparison.RoleCompare);
            foreach (Role system in systems)
            {
                //SYSTEM MENU
                List<AccessControl> systemControl = (List<AccessControl>)m.FIBS.GetAccessControlsByRoleList(system.ID, 0);
                XmlElement systemMenu = xmlDoc.CreateElement("System");
                systemMenu.SetAttribute("title", CultureManager.GetResource(string.Format("Master_{0}Menu", systemControl[0].Name), language.Value));
                systemMenu.SetAttribute("navURL", systemControl[0].Value);
                systemMenu.SetAttribute("tag", system.BelongsToSystemID.ToString());

                //ROLES MENU
                List<Role> roles = (List<DTO.Role>)LocalizeRoleList(m.FIBS.GetRolesForEmployeeList(employee.ID, system.BelongsToSystemID));
                roles.Sort(DTO.RoleComparison.RoleCompare);

                foreach (Role role in roles)
                {
                    XmlElement roleMenu = xmlDoc.CreateElement("Role");
                    roleMenu.SetAttribute("title", role.Name);
                    roleMenu.SetAttribute("navURL", "");
                    roleMenu.SetAttribute("imgURL", string.Format(@"./App_Themes/{0}/imgs/bullet_green.png", Session["Theme"].ToString()));
                   
                    //PAGES (ACCESSCONTROLS) MENU
                    List<AccessControl> accessControls = (List<AccessControl>)LocalizeAccesscontrolList(m.FIBS.GetAccessControlsByRoleList(role.ID, system.BelongsToSystemID));
                    accessControls.Sort(DTO.AccessControlComparison.AccesscontrolCompare);

                    foreach (AccessControl accessControl in accessControls)
                    {
                        if (accessControl.NewWindow != 2)
                        {
                            XmlElement accessControlMenu = xmlDoc.CreateElement("Page");
                            accessControlMenu.SetAttribute("title", accessControl.Name);
                            accessControlMenu.SetAttribute("imgURL", string.Format(@"./App_Themes/{0}/imgs/bullet_orange.png", Session["Theme"].ToString()));
                           
                            //Popup page
                            if (accessControl.NewWindow == 1)
                            {
                                accessControlMenu.SetAttribute("tag", "_blank" + accessControl.Value);
                            }
                            else //Inline page
                            {
                                accessControlMenu.SetAttribute("navURL", accessControl.Value);
                            }
                            roleMenu.AppendChild(accessControlMenu);
                        }
                    }
                    systemMenu.AppendChild(roleMenu);
                }
                xmlMenu.AppendChild(systemMenu);
            }


            //Bind XML elements to menu
            Infragistics.WebUI.UltraWebNavigator.ItemBinding bindingSystem = new Infragistics.WebUI.UltraWebNavigator.ItemBinding();
            bindingSystem.DataMember = "System";
            bindingSystem.ImageUrlField = "imgURL";
            bindingSystem.TargetUrlField = "navURL";
            bindingSystem.TextField = "title";
            bindingSystem.ToolTipField = "toolTip";
            bindingSystem.TagField = "tag";
            Infragistics.WebUI.UltraWebNavigator.ItemBinding bindingRole = new Infragistics.WebUI.UltraWebNavigator.ItemBinding();
            bindingRole.DataMember = "Role";
            bindingRole.ImageUrlField = "imgURL";
            bindingRole.TargetUrlField = "navURL";
            bindingRole.TextField = "title";
            bindingRole.ToolTipField = "toolTip";
            bindingRole.TagField = "tag";
            Infragistics.WebUI.UltraWebNavigator.ItemBinding bindingPage = new Infragistics.WebUI.UltraWebNavigator.ItemBinding();
            bindingPage.DataMember = "Page";
            bindingPage.ImageUrlField = "imgURL";
            bindingPage.TargetUrlField = "navURL";
            bindingPage.TextField = "title";
            bindingPage.ToolTipField = "toolTip";
            bindingPage.TagField = "tag";
            UltraWebMenu1.DataBindings.Add(bindingSystem);
            UltraWebMenu1.DataBindings.Add(bindingRole);
            UltraWebMenu1.DataBindings.Add(bindingPage);

            //Append XML menu to XML document
            xmlDoc.AppendChild(xmlMenu);
            xmlData.Data = xmlDoc.OuterXml;
            xmlData.XPath = "Menu/System";

            //Set XML document as menu datasource
            UltraWebMenu1.DataSource = xmlData;
            UltraWebMenu1.DataBind();

 

Hopefully there is an easy solution to this!

 

  • 475
    Verified Answer
    Offline posted

    Hi!

    I solved this issue myself!

    The ID of the XmlDatasource may NOT be static when applying the XmlDatasource at runtime, it must be random.  If the ID of the XmlDatasource is static the UltraWebMenu does not seem to know when the contents of the XmlDatasource is changed at runtime.

    To fix this I used the following solution to get a random XmlDatasource ID:

          XmlDataSource xmlData = new XmlDataSource();
          xmlData.ID = "xmlDataSourceFIBSMenu" + DateTime.Now.Ticks;

    By using the DateTime.Now.Ticks I ensure that that the XmlDataSoucre ID will never be the same :)

    Hopefully this can help someone that has a similar problem.