//这段代码很重要
protected override void InitializeCulture()
{
string culture = Request.QueryString["curlanguage"];
if (!String.IsNullOrEmpty(culture))
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(culture);
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ltlcountry.Text = Resources.language.country.ToString();
ltlcity.Text = Resources.language.city.ToString();
ltlcountry2.Text =(string)GetGlobalResourceObject("language", "country");
ltlcity2.Text=(string)GetGlobalResourceObject("language", "city");
}
}
body
{
font-family: Arial @宋体 font-size:12px;
}
#maindiv
{
margin: 20px;
padding: 10px;
height: 200px;
width: 200px;
border: solid 5px #C0C0C0;
text-align: center;
background-color: Olive;
}
body
{
font-family: Arial Verdana;
font-size: 12px;
}
#maindiv
{
margin: 20px;
padding: 10px;
height: 200px;
width: 200px;
border: solid 5px #C0C0C0;
text-align: center;
background-color: gray;
}
public class BaseLanguage : System.Web.UI.Page
{
protected override void InitializeCulture()
{
string culture = Request.QueryString["curlanguage"];
if (!String.IsNullOrEmpty(culture))
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(culture);
}
}
}
因为上面的这段代码是每个页面都必须要有的,所以这里把分给写到一个专门的类中,并继承 System.Web.UI.Page,然后每个页面再继承这个类就可以了
public partial class Test2 : BaseLanguage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
link.Href = Resources.language.pagestyle.ToString(); //页面的样式文件设置
imgLoading.Src = Resources.language.loadingImg.ToString(); //图片的路径
ltlcountry.Text = Resources.language.country.ToString();
ltlcity.Text = Resources.language.city.ToString();
ltlcountry2.Text = (string)GetGlobalResourceObject("language", "country");
ltlcity2.Text = (string)GetGlobalResourceObject("language", "city");
}
}
}