【发布时间】:2015-09-01 02:48:08
【问题描述】:
这是我创建自定义控件的第一次体验。我的真实示例要大得多,但为了清楚起见,将其归结为。最终,我需要尽可能多地隐藏自定义控件的属性,这样当我与团队的其他成员共享我的新控件时,他们只需要担心所需的少数属性。
我有一个名为 TimeNow 的控件,它继承 System.Web.UI.WebControls.Literal,基本上只是在网页上打印当前时间:
public class TimeNow : Literal
// Set to private so Text is hidden from the editor.
private string Text
{
get;
set;
}
protected override void Render(HtmlTextWriter writer)
{
// Get and write the time of now.
}
这工作,但看起来很笨重。当我将控件放在网页上时,我不再在智能感知中看到可用的文本,但我确实收到一条警告,指出我的文本正在隐藏继承的文本。有没有更好的方法来隐藏 Text 属性?
【问题讨论】:
标签: c# asp.net inheritance custom-controls