如何在智能感知支持下向 Web 控制适配器添加自定义属性?

发布于 2024-12-20 23:54:04 字数 902 浏览 7 评论 0 原文

我创建了一个继承自 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;
    }
}

我需要知道的两件事是:

  1. 如何使用中指定的值自动初始化此属性asp控件?
  2. 我该如何让 Intellisense 识别/显示该新属性?

I created a CheckBoxList Adapter that inherits from System.Web.UI.WebControls.Adapters.WebControlAdapter. Now, I would like to know how I can add a custom attribute to my adapter and how to have intellisense recognize that new attribute.

My attribute is called DisabledCssClass, and I would like to be able to write something like:

<asp:CheckBoxList ID="anID" 
    runat="server"  
    CssClass="checkBoxList"
    DisabledCssClass="SomeCssClass"
    DataSourceID="SomeDatasourceId" 
    DataTextField="SomeTextField" 
    DataValueField="SomeValueField"
    RepeatDirection="Vertical" 
    RepeatLayout="Table"
    RepeatColumns="4">
</asp:CheckBoxList>

In my adapter class, I added:

private string disabledCssClass;

public string DisabledCssClass
{
    get
    {
        return (disabledCssClass == null ? String.Empty : disabledCssClass);
    }
    set
    {
        disabledCssClass = value;
    }
}

The two things I need to know are:

  1. How do I do to get this property automatically initialized with the value specified in the asp control?
  2. How do I do to have Intellisense recognize/show that new attribute?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

望笑 2024-12-27 23:54:04

您无法通过 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.

溇涏 2024-12-27 23:54:04

使用 CategoryAttribute as:

[Category("Settings")]

从我的角度来看,以下内容就足够了:

public string DisabledCssClass { get; set; }

Decorate each property you want to be visible in markup with CategoryAttribute as:

[Category("Settings")]

From my point of view the following will be enough:

public string DisabledCssClass { get; set; }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文