Globalization - Change Lang by Image Click
Hi, I'm working on a project that changes the language when an image button is clicked.
I've succeeded in the mission using the DropDownList but I just can't figure out how to make it with the image buttons.
*Code with Dropdownlist*
Master Page: <asp:DropDownList ID="ddlLanguages" runat="server" AutoPostBack="true"> <asp:ListItem Text="English" Value="en-us" /> <asp:ListItem Text="French" Value="fr" /> </asp:DropDownList> Master Page.CS if (!this.IsPostBack) { if (ddlLanguages.Items.FindByValue(CultureInfo.CurrentCulture.Name) != null) { ddlLanguages.Items.FindByValue(CultureInfo.CurrentCulture.Name).Selected = true; } }
BasePage.CS(Class): public class BasePage : System.Web.UI.Page { protected override void InitializeCulture() { string language = "en-us"; //Detect User's Language. if (Request.UserLanguages != null) { //Set the Language. language = Request.UserLanguages[0]; } //Check if PostBack is caused by Language DropDownList. if (Request.Form["__EVENTTARGET"] != null && Request.Form["__EVENTTARGET"].Contains("ddlLanguages")) { //Set the Language. language = Request.Form[Request.Form["__EVENTTARGET"]]; } //Set the Culture. Thread.CurrentThread.CurrentCulture = new CultureInfo(language); Thread.CurrentThread.CurrentUICulture = new CultureInfo(language); } }
Default.aspx: <asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <asp:Label ID="Label1" Text="<%$Resources:Resource, Greeting %>" runat="server" Font-Bold="true" /> <br /> <br /> <span><%=Resources.Resource.GoodBye %></span> </asp:Content>
I have two image buttons(One for USA flag, The second one for France flag)
I also have two Resources(Resource.resx for English and Resource-fr.resx For France)
Please help!
Thanks in advance
0 comments:
Post a Comment