Property in UserControl does not keep value?

  • Thread starter Thread starter al
  • Start date Start date
A

al

Greetings,

I have a UserControl (UC) with a Sub inside it(trigered by a HTML
button inside the UC) to change a property inside the UC to a new
string value.

When the user clicks that button, a string changes the property value
to new value. However, when I click, the porpety is changed but it
does not keep that value and retains old value once it finishes
excution.

Any reason why? Or how should I persist the value of a propety in an
app.??

Code:

Class ChangeText()


Private txt As String

Private Sub SetText_ServerClick(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button2.ServerClick

NewText="NewValue"

End Sub

Property NewText() As String
Get
Return txt
End Get
Set(ByVal Value As String)
txt = Value 'this changes value fine
End Set
End Property

End Class

MTIA,
Grawsha
 
al said:
Greetings,

I have a UserControl (UC) with a Sub inside it(trigered by a HTML
button inside the UC) to change a property inside the UC to a new
string value.

When the user clicks that button, a string changes the property value
to new value. However, when I click, the porpety is changed but it
does not keep that value and retains old value once it finishes
excution.

Any reason why? Or how should I persist the value of a propety in an
app.??

Use Viewstate:

Property NewText() As String
Get
Return ViewState("NewText")
End Get
Set(ByVal Value As String)
ViewState("NewText") = Value 'this changes value fine
End Set
End Property

End Class
 
Back
Top