I try to create UserControl for switching Language/Country. There are two ImageButtons for two countries. After clicking
on one button, nothing happens. After second click on same button the language changes.
Can someone tell me, what I'm doing wrong?
Best Regards,
Gabriel
namespace gg.Controls
{
using System;
using System.IO;
using System.Threading;
using System.Globalization;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Language : UserControl
{
public Language()
{
}
public string Lang {
get { return (string)ViewState["LANGUAGE"]; }
set { ViewState["LANGUAGE"] = value; }
}
public void SelectLang( object source, CommandEventArgs e )
{
Lang = e.CommandName;
CultureInfo ci = CultureInfo.CreateSpecificCulture( e.CommandName );
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
}
protected override void OnLoad( EventArgs e )
{
ImageButton b = new ImageButton();
b.ID = "lang_de";
b.CommandName = "de";
b.Command += new CommandEventHandler( SelectLang );
if ( Lang == "de" )
b.ImageUrl = "../images/flag_de1.gif";
else
b.ImageUrl = "../images/flag_de0.gif";
Controls.Add( b );
b = new ImageButton();
b.ID = "lang_nl";
b.CommandName = "nl";
b.Command += new CommandEventHandler( SelectLang );
if ( Lang == "nl" )
b.ImageUrl = "../images/flag_nl1.gif";
else
b.ImageUrl = "../images/flag_nl0.gif";
Controls.Add( b );
Controls.Add( new LiteralControl( "<br/>Lang = " + Lang ) );
}
}
}