Aug 17, 2011, 11:47 AM
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
Thanks in advance.
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.csusing 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.