hi,
I just want simply to preserve some data in my usercontrol on postbacks.
so I added this property in my UserControl
Protected Property MyProperty() As String
Get
If Not ViewState("xxx") Is Nothing Then
Return ViewState("xxx")
Else
Return ""
End If
End Get
Set(ByVal value As String)
ViewState("xxx") = value
End Set
End Property
However I lost the viewstate value on postbacks. I checked that my
usercontrol has enabledviewstate=true.
What I m doing wrong ?
If I replace in the code ViewState by Session , the data is preserved,
however session won't work for me.(case of two pages using the
usercontrol in the same session)
Thank you
Riki - 28 Jul 2007 14:37 GMT
> hi,
>
[quoted text clipped - 22 lines]
> however session won't work for me.(case of two pages using the
> usercontrol in the same session)
Your code seems correct.
First, make sure that any code that initializes your property before
postback
is not executed again after postback.
Then, is your user control by any chance created dynamically (with New)?
In that case, make sure it gets the same id before and after the postback.
If not, viewstate is not preserved.

Signature
Riki