In <20************ ********@news.e ast.cox.net> Mike Hofer declaimed:
I have a webcontrol that has the following property defined:
<Category("Beha vior"), PersistenceMode (PersistenceMod e.Attribute),
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.
Content)> _ Public Property ForceDeterminat eState() As Boolean Get
Return CBool(Me.ViewSt ate("ForceDeter minateState"))
End Get
Set(ByVal value As Boolean)
Me.ViewState("F orceDeterminate State") = Value
End Set
End Property
Now, I have lots of other properties like this on my control, and they
all serialize just fine to the ASPX file and to the viewstate. This
one, however, loses its value whenever I build the project.
Neither the PersistenceMode Attribute nor the
DesignerSeriali zationVisibilit yAttribute seems to have any effect
whatsoever.
What am I doing wrong?
Thanks in advance,
Mike
I found the problem. The fix is as follows:
#Region "ForceDetermina teState"
<Category("Beha vior"), _
DefaultValue(Tr ue), _
Description("De termines whether or not the user can set the checkbox's
state to Indeterminate via mouse click."), _
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.
Content), _
PersistenceMode (PersistenceMod e.Attribute)> _
Public Property ForceDeterminat eState() As Boolean
Get
If Me.ViewState("F orceDeterminate State") Is Nothing Then
Return True
Else
Return CBool(Me.ViewSt ate("ForceDeter minateState"))
End If
End Get
Set(ByVal Value As Boolean)
Me.ViewState("F orceDeterminate State") = Value
End Set
End Property
#End Region
Turns out that when the program starts, there's no viewstate for the
property. I had assumed that the property would be set when the control
loaded, based on the settings in the ASPX file. This is apparently not
the case. However, the fix above worked beautifully.