By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,991 Members | 1,737 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,991 IT Pros & Developers. It's quick & easy.

Usercontrol - property value gets lost

P: n/a

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(ByVal sender As System.Object, ByVal e
As System.EventArgs) 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
ka****@monair.com (W)
Stellex Monitor Aerospace Corp.
-----------------------------------------------------------
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


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

Nov 21 '05 #2

P: n/a
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_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles SetVariable.Click

MyControl.DisplayValue = TextBox1.Text

End Sub

Private Sub GetVariable_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles GetVariable.Click

TextBox1.Text = MyControl.DisplayValue

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


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.