ASP.Net访问控件属性中的对象属性
我有两门这样的课ASP.Net访问控件属性中的对象属性,asp.net,reflection,Asp.net,Reflection,我有两门这样的课 现在,我想创建一个属性名为DataProperty的DataBoundLabel控件,在这里我可以传递属性名的完整路径 Namespace Application.Controls Public Class ExtendedLabel Inherits Label Public Property DataProperty As String Get If ViewState("D
现在,我想创建一个属性名为
DataProperty
的DataBoundLabel
控件,在这里我可以传递属性名的完整路径
Namespace Application.Controls
Public Class ExtendedLabel
Inherits Label
Public Property DataProperty As String
Get
If ViewState("DataProperty") Is Nothing Then
Return String.Empty
Else
Return CStr(ViewState("DataProperty"))
End If
End Get
Set(ByVal value As String)
ViewState("DataProperty") = value
End Set
End Property
Private Sub ExtendedLabel_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not String.IsNullOrEmpty(DataProperty) Then
Me.Text = GetReflectedValue()
End If
End Sub
Private Function GetReflectedValue() As String
//'Need suggestion here
End Function
End Class
End Namespace
用法是这样的
<cc:ExtendedLabel id="elName" runat="server" DataProperty="Business.Core.Settings.Name" />
请建议使用反射访问此值的方法
我只是想澄清一下,我希望能够访问任何命名空间的任何类中的任何属性,无论是静态的还是实例化的。因此,我不能使用中给出的声明性格式
<cc:ExtendedLabel id="elName" runat="server" DataProperty="Business.Core.Settings.Name" />