473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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(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
2 2100
Where are you assigning a value to you property? BTW: Your property
variable (saveVal) should probably be private.

Nov 21 '05 #2
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DraguVaso | last post by:
Hi, I'm having some weird behaviour, and I can't find any solution to this. I made a UserControl (uclCommands) which contains a Toolbar (ToolBar1) with Modifiers = Public. I put this...
4
by: Pieter Linden | last post by:
Hi, Hopefully it's just me missing something obvious (but at 2AM, not much is obvious, I guess...) I have a table of courses that people have taken (StudentID,CourseID) and the user selects a...
6
by: steve bull | last post by:
I created a usercontrol class, RGBColorSpace, which is derived from an abstract class, ColorSpace, but when I try to click on the design panel for the control I get an error message "Unable to...
1
by: Kepler | last post by:
I have a custom control that is thrown onto a UserControl that is thrown onto a WebForm. Basically, I've got a scenario where if my UserControl sets an attribute on the custom control in the ascx,...
1
by: Will Gillen | last post by:
I know this has probably been asked before, but I can't seem to find a solid answer in any of the archives. First, before my question, please forgive my limited knowledge of the event lifecycle...
4
by: Sam Martin | last post by:
Hi, I have got a User Control that contains for the sake of argument, a single DataList control. eg. <asp:DataList id="DataListMain" runat="server" RepeatDirection="Horizontal"...
3
by: Jeff | last post by:
Hey ASP.NET 2.0 This the ObjectDataSource in my UserControl, <asp:ObjectDataSource ID="odsMessage" runat="server" SelectMethod="ExecuteMessage" TypeName="AH.MyNetwork.BLL.Network.Message">...
6
by: MeowCow | last post by:
I have created a UserControl that encapsulates a third party data grid. My goal was to create my own DataSource and DataMember properties that forward the binding to the third party grid, then use...
3
by: Simon Verona | last post by:
Sorry for the repost, but this group seems to be more "active" than the group that I posted my question, and it's probably as valid here as there! I have a usercontrol, which contains a textbox...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.