Properties

M

Mike

Why does this work:
***********************
Public Class WebForm2
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code ".....

Private y As String = "Hello"

Property Prop() As String
Get
Return y
End Get
Set(ByVal Value As String)
y = Value
End Set
End Property

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Prop = "GoodBye"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Label1.Text = Prop
End Sub

End Class
***********************
....and not this?
***********************
Public Class WebForm2
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code ".....

Private y As String = "Hello"

Property Prop() As String
Get
Return y
End Get
Set(ByVal Value As String)
y = Value
End Set
End Property

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Label1.Text = Prop
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Prop = "GoodBye"
End Sub

End Class
***********************
Thanks in advance for your help
Mike
 
G

Guest

Change to

Private Shared Y As String = "Hello"

Then Change to

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Y = "GoodBye"
End Sub

You now have a static value that is updated and can be set to the Label when
you click. Not the best design, but it solves the problem.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
J

JohnFol

Can I presume in the 2nd example, you let the form open, click button 2 and
then button 1?

What do you get to suggest it "doesn't work"?
 
M

Mike

Yes John, your presumption is accurate.

Sorry, I should have been more clear.
Once the webform is open, I press button2, then button1!

Therefore, why does the value 'y' still post "Hello"? I set the value
to "Goodbye" by pressing button2. No?
 
M

Mike

Hello Cowboy,

thanks, that's better!

If you don't mind me asking, what is a better design you're refering
too?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top