User Control property is nothing

292 Views Asked by At

Using ASP.NET/VB.NET

I created a user control with a public property.

Public Class XXX
    Public Property MyProperty As String

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

In my parent form I set the property...

MyUserControl.XXX.MyProperty= "My Value"

When stepping thru the code I see that it's set correctly. But, when I call a method (MySub) in my user control (called from parent) MyProperty is nothing.

Is this out of scope? Why isn't it set to "My Value"?

1

There are 1 best solutions below

1
On

Do you have a private member declared to store the value?

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