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

Forums / Developing with Sitefinity / Language flag list issue when doing a postback

Language flag list issue when doing a postback

3 posts, 1 answered
  1. David van Geel
    David van Geel avatar
    59 posts
    Registered:
    19 Aug 2009
    06 Aug 2010
    Link to this post
    Hi,

    I am having a problem with the LanguageList user control posted in this forum some time ago displaying flag icons instead of text. When displaying pages it works just fine but when I do a postback of a form the original template (text options) is used.

    This is the code if the user control.
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Telerik.Web.UI;
      
    public partial class LanguageList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // tell the LanguageBar to use a custom template
            this.flagList.LayoutTemplate = new DefaultTemplate();
        }
      
        // Change the template for Language bar - use the custom LanguageFlagList to render markup
        private class DefaultTemplate : ITemplate
        {
            public void InstantiateIn(Control container)
            {
                // initialize the LanguageBarList
                LanguageFlagList list = new LanguageFlagList();
                // set the ID so that it is recognized by the container
                list.ID = "languageList";
                container.Controls.Add(list);
            }
        }
    }

    The InstantiateIn method is NOT executed during a postback. The Page_Load method is executed. Should I move the code in the Page_Load method to another method (CreateChildControls, OnInit, etc.)?

    Regards,


    David
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Aug 2010
    Link to this post
    Hi David van Geel,

    There are two options

    1. Skip the code you have now and use only the declaration below

    <%@ Register Namespace="Telerik.Localization.WebControls" TagPrefix="lng" Assembly="Telerik.Localization" %>
      
    <style type="text/css">  
    .langList li  
    {  
        float:left;  
        padding: 0px;  
        list-style-type:none; 
             
         
    </style
        
    <lng:LanguageBar  ID="list1" runat="server"
        <LayoutTemplate
            <lng:LanguageList CssClass="langList" ID="languageList" runat="server"></lng:LanguageList
        </LayoutTemplate
    </lng:LanguageBar>

    2. The second option is to instantiate control template inside PreRender

    protected void Page_Load(object sender, EventArgs e) 
        
               
            this.flagList.LayoutTemplate = this.Template; 
        
        
        protected override void OnInit(EventArgs e) 
        
            base.OnInit(e); 
            this.flagList.LayoutTemplate = this.Template; 
        
        
        private class DefaultTemplate : ITemplate 
        
            public void InstantiateIn(Control container) 
            
                LanguageFlagList list = new LanguageFlagList(); 
                list.ID = "languageList"
                list.CssClass = "langList"
                container.Controls.Add(list); 
            
        
        
        private ITemplate Template 
        
            get
            
                    return new DefaultTemplate(); 
        
            
        }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. David van Geel
    David van Geel avatar
    59 posts
    Registered:
    19 Aug 2009
    09 Aug 2010
    Link to this post
    Hi Ivan,

    I have implemented the second option. Works like a charm...

    Thanks,


    David
Register for webinar
3 posts, 1 answered