母版initializeculture发现错误覆盖没有合适的方法? [英] masterpage initializeculture no suitable method found to override error?
问题描述
我试图开发使用ASP.NET与C#
我的问题多语言网站是:我要让语言中我的母版支持切换,但是当我把InitializeCulture()内。masterpage.cs,我得到这个错误
I'm trying to develop a MultiLanguage web site using ASP.NET with C# My problem is: I want to make my MasterPage support switching among languages, but when i put the "InitializeCulture()" inside the masterpage.cs, I got this error.
这是我的代码:
public partial class BasicMasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.IsToday)
{
e.Cell.Style.Add("background-color", "#3556bf");
e.Cell.Style.Add("font-weight", "bold");
}
}
Dictionary<string, System.Globalization.Calendar> Calendars =
new Dictionary<string, System.Globalization.Calendar>()
{
{"GregorianCalendar", new GregorianCalendar()},
{"HebrewCalendar", new HebrewCalendar()},
{"HijriCalendar", new HijriCalendar()},
{"JapaneseCalendar", new JapaneseCalendar()},
{"JulianCalendar", new JulianCalendar()},
{"KoreanCalendar", new KoreanCalendar()},
{"TaiwanCalendar", new TaiwanCalendar()},
{"ThaiBuddhistCalendar", new ThaiBuddhistCalendar ()}
};
protected override void InitializeCulture()
{
if (Request.Form["LocaleChoice"] != null)
{
string selected = Request.Form["LocaleChoice"];
string[] calendarSetting = selected.Split('|');
string selectedLanguage = calendarSetting[0];
CultureInfo culture = CultureInfo.CreateSpecificCulture(selectedLanguage);
if (calendarSetting.Length > 1)
{
string selectedCalendar = calendarSetting[1];
var cal = culture.Calendar;
if (Calendars.TryGetValue(selectedCalendar, out cal))
culture.DateTimeFormat.Calendar = cal;
}
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
}
base.InitializeCulture();
}
}
我怎样才能创建一个基类?
How can I create a Base class?
推荐答案
该方法 InitializeCulture()
只存在于网页类,不是的母版类,这就是为什么你得到这个错误。
The method InitializeCulture()
exists only on the Page class, not the MasterPage class, and that's why you get that error.
要解决这个问题,你可以创建一个的BasePage
你所有的特定页面继承:
To fix this, you could create a BasePage
that all your specific pages inherit:
- 创建一个新的类(不是网上表格),称之为
的BasePage
,或任何你想 - 请继承它的System.Web.UI.Page 。
- 请所有其他页面继承了
的BasePage
- Create a new Class (not Webform), call it
BasePage
, or whatever you want. - Make it inherit System.Web.UI.Page.
- Make all your other pages inherit the
BasePage
.
下面是一个例子:
public class BasePage : System.Web.UI.Page
{
protected override void InitializeCulture()
{
//Do the logic you want for all pages that inherit the BasePage.
}
}
和特定的页面应该是这个样子:
And the specific pages should look something like this:
public partial class _Default : BasePage //Instead of it System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Your logic.
}
//Your logic.
}
这篇关于母版initializeculture发现错误覆盖没有合适的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!