using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Globalization; using System.Threading; /// <summary> /// Summary description for BasePage /// </summary> public class BasePage:System.Web.UI.Page { public const string LanguageDropDownID = "ctl00$ddlLanguage"; public const string PostBackEventTarget = "__EVENTTARGET"; public static CultureInfo Culture; public static DateTimeStyles Style; public BasePage() { // // TODO: Add constructor logic here // /*if (DateTime.Now < DateTime.Parse("03/31/2014") && DateTime.Now > DateTime.Parse("01/01/2010")) { Culture = CultureInfo.CreateSpecificCulture("en-GB"); Style = DateTimeStyles.None; } else throw new Exception("Server is Responding Please Contact to Server Operater");*/ } protected override void InitializeCulture() { /////////<REMARKS> ///Check if PostBack occured. Cannot use IsPostBack in this method ///as this property is not set yet. //////</REMARKS> if (Request[PostBackEventTarget] != null) { string controlID = Request[PostBackEventTarget]; if (controlID.Equals(LanguageDropDownID) || controlID.Equals("ddlLanguage")) { Session["LanguageChanged"] = true; string selectedValue = Request.Form[Request[PostBackEventTarget]].ToString(); switch (selectedValue) { case "1": SetCulture("en-GB", "en-GB"); break; case "2": SetCulture("hi-IN", "hi-IN"); break; default: break; } } else Session["LanguageChange"] = false; } else if (Session["MyUICulture"] == null) { SetCulture("hi-IN", "hi-IN"); Session["LanguageChanged"] = false; } else SetCulture(Session["MyUICulture"].ToString(), Session["MyUICulture"].ToString()); ///<remarks> ///Get the culture from the session if the control is tranferred to a ///new page in the same application. if(Session["MyUiCulture"] !=null && Session["MyUICulture"]!=null) { Thread.CurrentThread.CurrentUICulture=(CultureInfo)Session["MyUICulture"]; Thread.CurrentThread.CurrentCulture=(CultureInfo)Session["MyCulture"]; } base.InitializeCulture(); } /// Sets the current UICulture and CurrentCulture based on the arguments protected void SetCulture(string name, string local) { Thread.CurrentThread.CurrentUICulture = new CultureInfo(name); Thread.CurrentThread.CurrentCulture = new CultureInfo(local); ///<remarks> ///Saving the current thread's culture set by the User in the Session ///so that it can be used across the pages in the current application. Session["MyUICulture"] = Thread.CurrentThread.CurrentUICulture; Session["MyCulture"] = Thread.CurrentThread.CurrentCulture; } protected void Page_PreInit(Object sender, EventArgs e) { if(Session["MyUICulture"]!= null) { if (Session["MyCulture"].ToString() == "hi-IN") this.Page.Theme = "Hindi"; else this.Page.Theme = "English"; } else this.Page.Theme="English"; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)