用户控件属性没什么

时间:2015-06-09 23:42:02

标签: asp.net vb.net user-controls

使用ASP.NET / VB.NET

我使用公共属性创建了一个用户控件。

Public Class XXX
    Public Property MyProperty As String

    Public Sub MySub()
         If MyProperty Is Nothing Then
            ......

在我的父表单中,我设置了属性...

MyUserControl.XXX.MyProperty= "My Value"

当单步执行代码时,我发现它已正确设置。但是,当我在用户控件中调用一个方法(MySub)时(从父级调用)MyProperty什么都没有。

这是否超出范围?为什么不设置为“我的价值”?

1 个答案:

答案 0 :(得分:0)

您是否声明了存储值的私有成员?

Private _myProperty As String

Public Property MyProperty() As String
    Get
        Return _myProperty
    End Get
    Set(ByVal value As String)
        _myProperty = value
    End Set
End Property

Public Sub MySub()
    If Not String.IsNullOrEmpty(MyProperty) Then
        '...
    End If
End Sub