【发布时间】:2009-10-06 12:57:02
【问题描述】:
我将 TextBox WebControl 扩展为一种“DateTextBox”,它在代码隐藏中将其值作为属性 (DateValue) 公开:
public sealed class DateTextBox : TextBox
{
public DateTime ?DateValue
{
/* ToDateFromUserInterface() and ToUserInterfaceString() are both
extension methods */
get
{
return
(
String.IsNullOrEmpty(Text) ?
new DateTime?() :
Text.ToDateFromUserInterface()
);
}
set
{
if (value != null) Text = ((DateTime)value).ToUserInterfaceString();
}
}
}
鉴于此控件仅应与日期一起使用,因此没有理由从其父级继承 Text 属性。
有没有办法隐藏它?.. 除了实现NotImplementedException,像这样:
new public String Text
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
【问题讨论】:
标签: c# asp.net extensibility web-controls