ASP.NET 网页全球化&母版页 C# 3.0 中的本地化
我无法在全球化和母版页中使用以下代码本土化。它给出了代码部分中注释的错误“不包含 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
}
当我将此代码添加到母版页以外的其他页面时,它工作正常。在母版页中使用此代码是否有任何限制?
如果我能够在母版页中定义此代码,那么我不需要在每个文件中编写此代码。
我做错了什么吗,我已经包含了用于线程和全球化的文件,但它仍然在母版页中不起作用
I cant use the following code in Master page for Globalization & Localization. It gives the error as commented in the code part "does not contain a defination for 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
}
When i add this code to other pages other than Master Page it works fine. is there any restriction on using this code in Master Page.
If i am able to define this code in Master Page then i dont need to write this code in every file.
Am i doing something wrong, I have include File for threading and Globalization, Still it doesn't work in Master Page
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须在 Page 类中执行此操作(= 覆盖 InitializeCulture)。它在母版页中不起作用(MasterPage 是从 Control 派生的,而不是从 page 派生的)。我建议您实现一个从 Page 派生的基类,并从该类派生每个 Web 表单,然后您也只需编写一次代码。拥有自己的基类总是很方便的。
在 Visual Studio 中,添加一个新类 PageBase.cs:
当前区域性要么存储在会话中的某个下拉列表框中,要么通过查询字符串传递。我在示例中使用了列表框。
然后您从该页面派生您的 WebForm,如下所示:
You have to do this (= override InitializeCulture) in your Page class. It doesn't work in the master page (MasterPage is derived from Control, not from page). I would suggest that you implement a base class which is derived from Page and derive every web form from this class, then you also have to write the code only once. It is always handy to have your own base class.
In Visual Studio you add a new class PageBase.cs:
The current culture is either stored in some dropdown listbox, in the session or passed by query string. I used a listbox in the sample.
And then you derive your WebForm from this page like this: