我想强制控件的使用者在将控件放在页面上时为属性赋值.
在VisualStudio中,当您在用户控件上创建没有属性SRC或ALT的<img>标记时,它会加下划线,表示SRC和ALT是必需属性.我假设这只是编辑器对标记的一种特殊处理,但有没有办法为控件定义类似的行为?
如果控件具有如下定义的属性:
public object AProperty
{
get
{
if (ViewState["AProperty"] == null)
{
throw new Exception("AProperty is a required property of this control");
}
return ViewState["AProperty"];
}
set { ViewState["AProperty"] = value; }
}
Run Code Online (Sandbox Code Playgroud)
有没有办法使用自定义属性或其他可以在设计器中标记的东西?