|
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Globalization;
/// <summary>
/// BasePage for the common funtionality in all
/// the web pages of the site.
/// </summary>
public class BasePage: Page
{
/// <summary>
/// Default constructor
/// </summary>
public BasePage()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// The name of the culture selection dropdown list in the common header. We need this name
/// as we want to know the clintID of the language dropdown and we can't use ClientID or any other
/// control property as the control (dropdown) itself is not initialized yet. So we use the "nested"
/// dropdown name through which we will get the dropdown's value from the Request.Form[] collection.
/// </summary>
public const string LanguageDropDownID = "ctl00$cphHeader$Header1$ddlLanguage";
/// <summary>
/// The name of the PostBack event target field in a posted form. You can use this to see which
/// control triggered a PostBack: Request.Form[PostBackEventTarget] .
/// </summary>
public const string PostBackEventTarget = "__EVENTTARGET";
/// <summary>
/// Overriding the InitializeCulture method to set the user selected
/// option in the current thread. Note that this method is called much
/// earlier in the Page lifecycle and we don't have access to any controls
/// in this stage, so have to use Form collection.
/// </summary>
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)
{
///<remarks>
///Get the id of the control which triggered the PB
///Then we need to match this ID with the DropDown's ID
///to check if the dropdown was clicked and not some other control.
///</remarks>
string controlID = Request[PostBackEventTarget];
if (controlID.Equals(LanguageDropDownID))
{
string selectedValue = Request.Form[Request[PostBackEventTarget]].ToString();
switch (selectedValue)
{
case "0": SetCulture("hi-IN", "hi-IN");
break;
case "1": SetCulture("en-US", "en-US");
break;
case "2": SetCulture("en-GB", "en-GB");
break;
case "3": SetCulture("fr-FR", "fr-FR");
break;
default: break;
}
}
}
base.InitializeCulture();
}
/// <summary>
/// Sets the current UICulture and CurrentCulture based on
/// the arguments
/// </summary>
/// <param name="name"></param>
/// <param name="locale"></param>
protected void SetCulture(string name, string locale)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(name);
Thread.CurrentThread.CurrentCulture = new CultureInfo(locale);
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.