1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Language Selector Error

Language Selector Error

33 posts, 0 answered
  1. Volkan Demirpence
    Volkan Demirpence avatar
    12 posts
    Registered:
    11 Nov 2006
    18 Oct 2011
    Link to this post
    I had  "The ID 'languagesRepeater' is already used by another control." errror.
    I want to show flags with image button instead of hyper link.

    My template file :
    01.<%@ Control Language="C#" %>
    02.<%@ Register TagPrefix="sfFields" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields" %>
    03.<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
    04.   
    05.<div runat="server" id="controlWrapper">
    06.   
    07.    <asp:Panel ID="errorsPanel" runat="server" CssClass="sfErrorSummary" />
    08.   
    09.    <sf:ConditionalTemplateContainer ID="sfLangSelectorConditionalTemplateContainer" runat="server">
    10.        <Templates>
    11.            <sf:ConditionalTemplate Left="SelectorType" Operator="Equal" Right="Horizontal" runat="server">
    12.                <asp:Repeater ID="LanguagesRepeater" runat="server"
    13.                    <ItemTemplate>
    14.                            <li>
    15.                            <asp:ImageButton ID="imgLnkButton" runat="server" />
    16.                        </li>
    17.                    </ItemTemplate
    18.                </asp:Repeater>
    19.            </sf:ConditionalTemplate>
    20.            <sf:ConditionalTemplate Left="SelectorType" Operator="Equal" Right="Vertical" runat="server">
    21.                <asp:Repeater ID="LanguagesRepeater" runat="server">
    22.                    <HeaderTemplate>
    23.                        <ul>
    24.                    </HeaderTemplate>
    25.                    <ItemTemplate>
    26.                         
    27.                    </ItemTemplate>
    28.                    <FooterTemplate>
    29.                        </ul>
    30.                    </FooterTemplate>
    31.                </asp:Repeater>
    32.            </sf:ConditionalTemplate>
    33.            <sf:ConditionalTemplate Left="SelectorType" Operator="Equal" Right="DropDown" runat="server">
    34.                  
    35.            </sf:ConditionalTemplate>
    36.        </Templates>
    37.    </sf:ConditionalTemplateContainer>
    38.</div>

    My custom control codes :
    001.using System;
    002.using System.Collections.Generic;
    003.using System.Linq;
    004.using System.Web;
    005.using Telerik.Sitefinity.Localization.Web.UI;
    006.using System.Globalization;
    007.using Telerik.Sitefinity.Configuration;
    008.using Telerik.Sitefinity.Modules.Pages.Configuration;
    009.using Telerik.Sitefinity.Modules.Pages;
    010.using Telerik.Sitefinity.Abstractions;
    011.using Telerik.Sitefinity.Model;
    012.using System.Threading;
    013.using System.Web.UI.WebControls;
    014.using Telerik.Sitefinity.Localization.UrlLocalizationStrategies;
    015.using Telerik.Sitefinity.Pages.Model;
    016.using Telerik.Sitefinity.Web;
    017.using Telerik.Sitefinity;
    018.using Telerik.Sitefinity.Web.UI; 
    019.  
    020.namespace SitefinityWebApp
    021.{
    022.    public class MyLanguageSelector : LanguageSelectorControl
    023.    {
    024.        private const string customLayoutTemplateName = "SitefinityWebApp.customcontrol.MyLanguageSelector.ascx";
    025.        private const string customlayoutTemplatePath = "~/customcontrol/MyLanguageSelector.ascx";
    026.     
    027.        new private Telerik.Sitefinity.Pages.Model.PageNode homePageNode;
    028.         
    029.         
    030.  
    031.        protected override string LayoutTemplateName
    032.        {
    033.            get
    034.            {
    035.                return MyLanguageSelector.customLayoutTemplateName;
    036.            }
    037.        }
    038.  
    039.        public override string LayoutTemplatePath
    040.        {
    041.            get
    042.            {
    043.                return MyLanguageSelector.customlayoutTemplatePath;
    044.            }
    045.        }
    046.  
    047.        protected override void InitializeControls( GenericContainer container)
    048.        {
    049.            //base.InitializeControls(container);
    050.            var settings = AppSettings.CurrentSettings;
    051.            List<CultureInfo> languages = new List<CultureInfo>();
    052.            //if (this.MissingTranslationAction == NoTranslationAction.HideLink)
    053.            //{
    054.            //    languages.AddRange(this.usedLanguages);
    055.            //}
    056.            //else
    057.            //{
    058.  
    059.                languages.AddRange(settings.DefinedFrontendLanguages);
    060.                PageManager pm = PageManager.GetManager();
    061.                var homePageId = Config.Get<PagesConfig>().HomePageId;
    062.                if (homePageId != Guid.Empty)
    063.                {
    064.                    this.homePageNode = pm.GetPageNode(homePageId);
    065.                }
    066.            //}
    067.            CultureInfo currentLanguage = Thread.CurrentThread.CurrentUICulture;
    068.            IEnumerable<CultureInfo> shownLanguages;
    069.            if (this.ShowCurrentLanguage == false && this.SelectorType != LanguageSelectorType.DropDown)
    070.            {
    071.                shownLanguages = languages.Where(ci => ci.Equals(currentLanguage) == false);
    072.            }
    073.            else
    074.            {
    075.                shownLanguages = languages;
    076.               
    077.            }
    078.            this.LanguagesRepeater.DataSource = shownLanguages;
    079.            this.LanguagesRepeater.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(languagesRepeater_ItemDataBound);
    080.            this.LanguagesRepeater.DataBind();
    081.        
    082.  
    083.        protected void languagesRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    084.        {
    085.            try
    086.            {
    087.                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    088.                {
    089.                    CultureInfo item = e.Item.DataItem as CultureInfo;
    090.                    ImageButton imgLanguage = e.Item.FindControl("imgLnkButton") as ImageButton; 
    091.                       
    092.                       
    093.                    imgLanguage.ImageUrl = "../images/" + item.TwoLetterISOLanguageName + ".png";
    094.                    imgLanguage.ToolTip = item.DisplayName;
    095.                       
    096.                    UrlLocalizationService s = ObjectFactory.Resolve<UrlLocalizationService>();
    097.                    imgLanguage.PostBackUrl = s.ResolvePageUrl(this.node, item);
    098.                }
    099.            }
    100.            catch (Exception ex)
    101.            {
    102.                throw ex;
    103.            }
    104.        }
    105.  
    106.        private void GetCurrentPage()
    107.        {
    108.            try
    109.            {
    110.                var actualSitemapNode = SiteMapBase.GetActualCurrentNode();
    111.  
    112.                PageManager pm = PageManager.GetManager();
    113.  
    114.                var homePageId = Config.Get<PagesConfig>().HomePageId;
    115.                //IEnumerable<CultureInfo> availableLanguages = null;
    116.  
    117.                Guid nodeId;
    118.                if (actualSitemapNode != null)
    119.                {
    120.                    nodeId = actualSitemapNode.Id;
    121.                }
    122.                else
    123.                {
    124.                    nodeId = homePageId;
    125.                }
    126.  
    127.  
    128.                this.node = pm.GetPageNode(nodeId);
    129.  
    130.                //if (actualSitemapNode != null)
    131.                //{
    132.                //    availableLanguages = actualSitemapNode.AvailableLanguages;
    133.                //}
    134.                //else
    135.                //{
    136.                //    availableLanguages = this.node.AvailableCultures;
    137.                //}
    138.  
    139.            }
    140.            catch (Exception ex)
    141.            {
    142.                throw ex;
    143.            }
    144.        }
    145.  
    146.    }
    147.}

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    19 Oct 2011
    Link to this post
    Hi Volkan,

    We changes the template of the LanguageSelectorControl. There is a LanguageSelectorType here you can switch between the modes.

    <%@ Control Language="C#" %>
    <%@ Register TagPrefix="sfFields" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
     
    <div runat="server" id="controlWrapper">
     
        <asp:Panel ID="errorsPanel" runat="server" CssClass="sfErrorSummary" />
     
        <sf:ConditionalTemplateContainer ID="sfLangSelectorConditionalTemplateContainer" runat="server">
            <Templates>
                <sf:ConditionalTemplate Left="SelectorType" Operator="Equal" Right="Horizontal" runat="server">
                    <asp:Repeater ID="languagesRepeater_horizontal" runat="server">
                        <HeaderTemplate>
                            <ul id="langsWrapper" class="sflanguagesHorizontalList">
                        </HeaderTemplate>
                        <ItemTemplate>
                            <li runat="server" id="langHolder" class="sflanguageItem">
                                <a runat="server" id="langLink" href="" class="sflanguageLnk"><span runat="server" id="langName"></span></a>
                            </li>
                        </ItemTemplate>
                        <FooterTemplate>
                            </ul>
                        </FooterTemplate>
                    </asp:Repeater>
                </sf:ConditionalTemplate>
                <sf:ConditionalTemplate Left="SelectorType" Operator="Equal" Right="Vertical" runat="server">
                    <asp:Repeater ID="languagesRepeater_vertical" runat="server">
                        <HeaderTemplate>
                            <ul id="langsWrapper" class="sflanguagesVerticalList">
                        </HeaderTemplate>
                        <ItemTemplate>
                            <li runat="server" id="langHolder" class="sflanguageItem">
                                <a runat="server" id="langLink" href="" class="sflanguageLnk"><span runat="server" id="langName"></span></a>
                            </li>
                        </ItemTemplate>
                        <FooterTemplate>
                            </ul>
                        </FooterTemplate>
                    </asp:Repeater>
                </sf:ConditionalTemplate>
                <sf:ConditionalTemplate Left="SelectorType" Operator="Equal" Right="DropDown" runat="server">
                    <div class="sflanguagesDropDownList">
                        <asp:DropDownList runat="server" ID="langsSelect" CssClass="sflanguagesDropDown"></asp:DropDownList>
                    </div>
                </sf:ConditionalTemplate>
            </Templates>
        </sf:ConditionalTemplateContainer>
    </div>


    Try using the VirtualPathProvider to register your template.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Volkan Demirpence
    Volkan Demirpence avatar
    12 posts
    Registered:
    11 Nov 2006
    19 Oct 2011
    Link to this post
    Hi Ivan,

     I changed the template with yours. It's ok now. Thanks a lot.
33 posts, 0 answered
1 2