Usercontrol - property value gets lost

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Kahrau

    #1

    Usercontrol - property value gets lost




    I need some help passing data to and from a usercontrol.
    In the following Property DisplayValue,
    If I hard code a return value (Return "Test Data"), then the data gets
    returned.
    If I work with any kind of assigned value, the return value is blank!
    Any idea on what I am doing wrong?




    Public Class UserControl1
    Public saveVal As String

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
    As System.EventArg s) Handles Button1.Click
    DisplayValue = TextBox1.Text
    End Sub


    Public Property DisplayValue() As String
    Get
    If saveVal <> "" Then
    Return saveVal ' "Test Data" ' TextBox1.Text
    Else
    Return "Lost Value"
    End If

    End Get
    Set(ByVal Value As String)
    saveVal = Value
    End Set
    End Property


    End Class

    -----------------------------------------------------------
    Gary Kahrau - VP
    kahrau@monair.c om (W)
    Stellex Monitor Aerospace Corp.
    -----------------------------------------------------------
  • Chris Dunaway

    #2
    Re: Usercontrol - property value gets lost

    Where are you assigning a value to you property? BTW: Your property
    variable (saveVal) should probably be private.

    Comment

    • Robert S. Liles

      #3
      Re: Usercontrol - property value gets lost

      This works just fine on my machine.
      _______________ _______________ _______

      Public Class Form1

      Inherits System.Windows. Forms.Form



      'Windows Form Designer generated code



      Dim MyControl As New UserControl1()



      Private Sub SetVariable_Cli ck(ByVal sender As System.Object, _

      ByVal e As System.EventArg s) Handles SetVariable.Cli ck



      MyControl.Displ ayValue = TextBox1.Text



      End Sub



      Private Sub GetVariable_Cli ck(ByVal sender As System.Object, _

      ByVal e As System.EventArg s) Handles GetVariable.Cli ck



      TextBox1.Text = MyControl.Displ ayValue



      End Sub

      End Class



      Public Class UserControl1



      Private saveVal As String



      Public Property DisplayValue() As String

      Get

      If saveVal <> "" Then

      Return saveVal

      Else

      Return "Lost Value"

      End If



      End Get

      Set(ByVal Value As String)

      saveVal = Value

      End Set

      End Property

      End Class






      Comment

      Working...