ASP.NET Localization doesn't work with EXT.Net controls

  1. #1

    ASP.NET Localization doesn't work with EXT.Net controls

    Hi,

    I'm building a multilanguage web site using Ext.Net and ASP.NET Localization. The user must choose a language in a Ext.Net combobox (with autopostback) before login, but it does not change the texts in Ext.Net controls when the user changes the language (always showing FieldLabel texts after reloading the page). I have searched for solutions in the Ext.Net forums, but I haven't find useful examples.

    This is my code:

    Default.aspx
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" culture="auto" meta:resourcekey="PageResource1" uiculture="auto" %>
    
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Localization</title>
        <style type="text/css">
            .icon-combo-item {
    	        background-repeat: no-repeat ! important;
    	        background-position: 3px 50% ! important;
    	        padding-left: 24px ! important;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" LicenseKey="" 
                Locale="es-ES" StopIDModeInheritance="False" />
            
            <ext:Store ID="Store1" runat="server" meta:resourcekey="Store1Resource1" 
                SerializationMode="Simple" StopIDModeInheritance="False">
                <Reader>
                    <ext:ArrayReader>
                        <Fields>
                            <ext:RecordField Name="iconCls" />
                            <ext:RecordField Name="name" />
                            <ext:RecordField Name="value" />
                        </Fields>
                    </ext:ArrayReader>
                </Reader>            
            </ext:Store>
                            
            <ext:Window 
                ID="Window1" 
                runat="server" 
                Closable="False"
                Resizable="False"
                Height="150px" 
                Icon="Lock" 
                Title="Login"
                Draggable="False"
                Width="350px"
                Modal="True"
                Padding="5"
                Layout="Form" meta:resourcekey="Window1Resource1" 
                StopIDModeInheritance="False">
                <Items>
                    <ext:TextField 
                        ID="txtUsername" 
                        runat="server" 
                        ReadOnly="true"
                        FieldLabel="Username" 
                        AllowBlank="false"
                        BlankText="Your username is required."
                        Text="Demo" meta:resourcekey="txtUsernameResource1"
                        />
                    <ext:TextField 
                        ID="txtPassword" 
                        runat="server" 
                        ReadOnly="true"
                        InputType="Password" 
                        FieldLabel="Password" 
                        AllowBlank="false" 
                        BlankText="Your password is required."
                        Text="Demo" meta:resourcekey="txtPasswordResource1"
                        />
                    <ext:ComboBox ID="cbLanguage" runat="server" AutoPostBack="True" 
                        DisplayField="name" Editable="False" FieldLabel="Language" StoreID="Store1" 
                        TriggerAction="All" ValueField="value" AutoPostBackEvent="Change" 
                        OnItemSelected="cbLanguage_ItemChanged" AutoRender="False" 
                        HiddenName="cbLanguage_Value" meta:resourcekey="cbLanguageResource1" >
                        <Template ID="tmpLanguage" runat="server">
                            <Html>
                                
    
                                <tpl for=".">
                                    <div class="x-combo-list-item icon-combo-item {iconCls}">
                                        {name}
                                    </div>
                                </tpl>
                            </Html>
                        </Template>
                        <Listeners>
                            <Select Handler="this.setIconCls(record.get('iconCls'));" />
                        </Listeners>
                    </ext:ComboBox>
                </Items>
                <Buttons>
                    <ext:Button ID="Button1" runat="server" Text="Login" Icon="Accept" 
                        meta:resourcekey="Button1Resource1">
                        <DirectEvents>
                            <Click OnEvent="Button1_Click" Success="Window1.close();">
                                <EventMask ShowMask="true" Msg="Verifying..." MinDelay="1000" />
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:Window>
        </form>
    </body>
    </html>
    Default.aspx.cs
    using System;
    using Ext.Net;
    using System.Globalization;
    
    public partial class _Default : System.Web.UI.Page 
    {
        protected override void InitializeCulture()
        {
            string language = string.Empty;
    
            try
            {
                if (Request.Form["cbLanguage_Value"] != null)
                {
                    language = Request.Form["cbLanguage_Value"].ToString();
                    if (language == string.Empty)
                    {
                        if (Session["Language"] != null)
                            language = Session["Language"].ToString();
                        else
                            language = "es-ES";
                    }
                }
                else
                {
                    CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture;
                    Session["Language"] = ci.IetfLanguageTag;
                    language = (String)Session["Language"];
                }
    
                System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(language);
                System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
    
                base.InitializeCulture();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Store1.DataSource = new object[]
                {
                    new object[] { ResourceManager.GetIconClassName(Icon.FlagEs), "Español", "es-ES"},
                    new object[] { ResourceManager.GetIconClassName(Icon.FlagUs), "English", "en-US"},
                };
    
            this.Store1.DataBind();
    
            ResourceManager1.RegisterIcon(Icon.FlagEs);
            ResourceManager1.RegisterIcon(Icon.FlagUs);
        }
    
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            // Do some Authentication...
    
            // Then user send to application
            Response.Redirect("Desktop.aspx");
        }
    
        protected void cbLanguage_ItemChanged(object sender, EventArgs e)
        {
            Session["Language"] = this.cbLanguage.SelectedItem.Value;
            this.Page.UICulture = Session["Language"].ToString();
        }
    }
    What is wrong with this code?
    Thanks in advance.
  2. #2
    If you add ASP.NET control to that page then does the localization works for that control?
  3. #3
    Hi Vladimir,

    I have added an ASP.NET control to the page and localization doesn't work for this control, but I don't know the reason.
  4. #4
    I have found a mistake in my .resx files and now localization works with Ext.Net controls. It was my fault! :S
    This thread can be marked as closed.

Similar Threads

  1. Postback doesn't work with asp controls
    By collegeminer in forum 2.x Help
    Replies: 4
    Last Post: Aug 16, 2012, 3:38 AM
  2. Replies: 5
    Last Post: Nov 03, 2011, 2:39 AM
  3. [CLOSED] localization for controls in gridpanel
    By farisqadadeh in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jun 30, 2011, 4:55 PM
  4. [1.0RC]MultiHeader doesn't work.
    By firebank in forum 1.x Help
    Replies: 1
    Last Post: Nov 11, 2010, 4:06 PM
  5. tabpanel doesn't work in IE8
    By maryam in forum 1.x Help
    Replies: 3
    Last Post: Aug 18, 2010, 5:49 AM

Tags for this Thread

Posting Permissions