ASP.. NET网页全球化c# 3.0版版页的本地化
本文关键字:本地化 0版 NET 网页 全球化 ASP | 更新日期: 2023-09-27 18:19:09
我不能在全球化的母版页面中使用以下代码&本地化。它给出了代码部分"不包含InitializeCulture的定义"中注释的错误
protected override void InitializeCulture()
{
if (Request["Language"] != null)
{
//String selectedLanguage = Request["Language"];
// code wil go here
}
base.InitializeCulture();
//base.InitializeCulture gives error as mentioned in the next line
//does not contain a defination for InitializeCulture
}
当我将此代码添加到其他页面,而不是母版页它工作正常。在母版页中使用此代码有任何限制吗?
如果我能够在母版页中定义此代码,那么我不需要在每个文件中编写此代码。
我做错了什么,我有包括文件线程和全球化,仍然不工作在母版页
你必须在你的Page类中这样做(= override InitializeCulture)。它在母版页中不起作用(母版页派生自Control,而不是page)。我建议你实现一个基类,它是从Page派生的,并从这个类派生出每个web表单,然后你也必须只写一次代码。有自己的基类总是很方便的。
在Visual Studio中添加一个新类PageBase.cs:
public class FormBase : Page
{
protected override InitializeCulture()
{
if (Request.Form["lbCulture"] != null)
{
String selectedLanguage = Request.Form["lbCulture"];
UICulture = selectedLanguage;
Culture = selectedLanguage;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);
}
base.InitializeCulture();
}
}
当前区域性要么存储在某个下拉列表框中,要么存储在会话中,要么通过查询字符串传递。我在示例中使用了一个列表框。
然后像这样从这个页面派生WebForm:
public class Default : FormBase // instead of deriving from Page