如何在智能感知支持下向 Web 控制适配器添加自定义属性?
我创建了一个继承自 System.Web.UI.WebControls.Adapters.WebControlAdapter 的 CheckBoxList 适配器。现在,我想知道如何向适配器添加自定义属性以及如何让智能感知识别该新属性。
我的属性称为DisabledCssClass,我希望能够编写如下内容:
<asp:CheckBoxList ID="anID"
runat="server"
CssClass="checkBoxList"
DisabledCssClass="SomeCssClass"
DataSourceID="SomeDatasourceId"
DataTextField="SomeTextField"
DataValueField="SomeValueField"
RepeatDirection="Vertical"
RepeatLayout="Table"
RepeatColumns="4">
</asp:CheckBoxList>
在我的适配器类中,我添加了:
private string disabledCssClass;
public string DisabledCssClass
{
get
{
return (disabledCssClass == null ? String.Empty : disabledCssClass);
}
set
{
disabledCssClass = value;
}
}
我需要知道的两件事是:
- 如何使用中指定的值自动初始化此属性asp控件?
- 我该如何让 Intellisense 识别/显示该新属性?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法通过 WebControlAdapter 将自定义属性添加到 Web 控件(请参阅“控件适配器的缺点”http: //www.singingeels.com/Articles/How_To_Control_Adapters.aspx)。
您最好的方法是创建自己的继承自 CheckBoxList 的类(本文很旧,但可能仍然适用https://web.archive.org/web/20211020203142/https://www.4guysfromrolla.com/articles/100103-1.aspx),创建您自己的 UserControl 或创建您的自己的服务器控件。我会选择选项 1 或 2。
You cannot add custom properties to a web control via a WebControlAdapter (refer to "Drawbacks of Control Adapters" http://www.singingeels.com/Articles/How_To_Control_Adapters.aspx).
Your best approach would be to either create your own class inheriting from CheckBoxList (this article is old but probably still applicable https://web.archive.org/web/20211020203142/https://www.4guysfromrolla.com/articles/100103-1.aspx), create your own UserControl or create your own ServerControl. I'd go with option 1 or 2.
使用 CategoryAttribute as:
从我的角度来看,以下内容就足够了:
Decorate each property you want to be visible in markup with CategoryAttribute as:
From my point of view the following will be enough: