PRB: Webcontrol Property Lost On Build

M

Mike Hofer

I have a webcontrol that has the following property defined:

<Category("Behavior"), PersistenceMode(PersistenceMode.Attribute), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Property ForceDeterminateState() As Boolean
Get
Return CBool(Me.ViewState("ForceDeterminateState"))
End Get
Set(ByVal value As Boolean)
Me.ViewState("ForceDeterminateState") = 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 PersistenceModeAttribute nor the DesignerSerializationVisibilityAttribute seems to have any effect whatsoever.

What am I doing wrong?

Thanks in advance,

Mike
 
M

Mike Hofer

In said:
I have a webcontrol that has the following property defined:

<Category("Behavior"), PersistenceMode(PersistenceMode.Attribute),
DesignerSerializationVisibility(DesignerSerializationVisibility.
Content)> _ Public Property ForceDeterminateState() As Boolean Get
Return CBool(Me.ViewState("ForceDeterminateState"))
End Get
Set(ByVal value As Boolean)
Me.ViewState("ForceDeterminateState") = 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 PersistenceModeAttribute nor the
DesignerSerializationVisibilityAttribute 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 "ForceDeterminateState"
<Category("Behavior"), _
DefaultValue(True), _
Description("Determines whether or not the user can set the checkbox's
state to Indeterminate via mouse click."), _
DesignerSerializationVisibility(DesignerSerializationVisibility.
Content), _
PersistenceMode(PersistenceMode.Attribute)> _
Public Property ForceDeterminateState() As Boolean
Get
If Me.ViewState("ForceDeterminateState") Is Nothing Then
Return True
Else
Return CBool(Me.ViewState("ForceDeterminateState"))
End If
End Get
Set(ByVal Value As Boolean)
Me.ViewState("ForceDeterminateState") = 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.
 

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

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top