【问题标题】:How can I expose a public property of a server control in the Properties window?如何在“属性”窗口中公开服务器控件的公共属性?
【发布时间】:2012-07-18 20:16:54
【问题描述】:

我有一个带有一些公共属性的 ASP.NET 服务器控件。

如果我将服务器控件放到窗体上,我可以从代码隐藏中访问这些属性。但我想在表单设计器的“属性”窗口中设置它们。

属性只是字符串和布尔值,而不是复杂类型。 我正在使用 Visual Studio 2010 和 .NET 4.0。

如何在设计模式下向“属性”窗口公开服务器控件属性?

【问题讨论】:

    标签: asp.net visual-studio-2010 custom-server-controls


    【解决方案1】:

    这是一个老歌,但很好。看起来像你在找什么。 Adding Design-Time Support to ASP.NET Controls

    这是一篇更新的文章:Design-Time Attributes for Components

    【讨论】:

    • 完美!这正是我所需要的。
    【解决方案2】:

    使用Browsable 属性装饰器

    //C#
    [Browsable(true)]
     public string MyProperty {
        get {
    
        }
        set {
    
        }
     }
    
     'VB
    <Browsable(True)> _
    Public Property MyProperty() As String
        Get
    
        End Get
        Set
    
        End Set 
    End Property
    

    【讨论】:

      猜你喜欢
      • 2020-04-11
      • 1970-01-01
      • 2015-09-30
      • 2014-10-10
      • 1970-01-01
      • 1970-01-01
      • 2011-10-07
      • 2018-05-22
      • 1970-01-01
      相关资源
      最近更新 更多