WebControl Design View Persist Problem

T

Todd Lucas

I'm having some weird things happen in design view while editing a custom collection - I've been at this for about 4 weeks now, and have tried all the different combinations of persistence settings (DesignerSerializationVisibility, PersistenceMode, etc) there is, and all to no avail! I'm hoping someone here can help ..

Environment: VS.NET 2003 v7.1.3088, Win2000 v5.00.2195 SP3, IE6 v6.0.2800.1106C

The problem is one of collection item persistence. The problem can be repeated by using the following steps

1) create new webform, and drop C3Menu control on it from Toolbox
2) click control to select it
3) click ellipse button on the MenuItems property to edit collection (via standard CollectionEditor)
4) add a new item, and click Ok button to save changes / close collection editor
5) switch to HTML view - changes are persisted ok
6) switch back to design view, and run the test project
7) control appears fine on webform, with all items listed
8) close webform to return to design view
9) click control to select it
10) click ellipse button on the MenuItems property to edit collection (via standard CollectionEditor)
11) add a new item, and click Ok button to save changes / close collection editor
12) switch to HTML view - changes are NOT persisted

It gets even weirder, because if I repeat steps 9-12 a second time (right after doing all 12) to add another new item, the previous item AND the second new item are persisted

If I remove the "SET" accessor on the MenuItems property in the C3Menu class, a new problem is presented: "Design View: Error creating control - '' could not be set on property MenuItems". This problem occurs if I close the webform after adding items to the collection, and try to reopen it. The application still runs ok, and the control is presented properly on the webform at run time, but the designer complains that the control cannot be created (above message) - I then cannot access any properties for the control in design view, but can add new items in the HTML view and they appear fine on the webform at run time

Any ideas? I would be happy to send the full source code to anyone that wants to help. Any help would be appreciated

Thanks - Tod

The Code (snippets)

[code

C3Menu Class

<DefaultEvent("ItemClick"),
Description("Server Control - Menu Definition."),
ParseChildren(True, "MenuItems"), PersistChildren(False),
ToolboxData("<{0}:C3Menu runat=server></{0}:C3Menu>")>
Public Class C3Menu : Inherits System.Web.UI.WebControls.WebContro
...
Dim _menuitems As New C3MenuItemCollectio
...
<Category("Menu Properties"), NotifyParentProperty(True),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerDefaultProperty),
Description("Collection of Menu Items this object will display.")>
ReadOnly Property [MenuItems]() As C3MenuItemCollectio
Ge
Return _menuitem
End Ge
' ** Note - SET causes control creation errors when the page is loaded
Set(ByVal Value As C3MenuItemCollection
If Not IsNothing(Value) Then _menuitems = Valu
End Se
End Propert
...

C3MenuItemCollection Class

Public Class C3MenuItemCollection : Inherits System.Collections.CollectionBas

Public Sub New(
MyBase.New(
End Su

Default Public Property Item(ByVal index As Integer) As C3MenuIte
Ge
Return CType(Me.List(index), C3MenuItem
End Ge
Set(ByVal Value As C3MenuItem
Me.List(index) = Valu
End Se
End Propert

Public Function Add(ByVal value As C3MenuItem) As Intege
Return Me.List.Add(value
End Functio

Public Function Contains(ByVal value As C3MenuItem) As Boolea
Return Me.List.Contains(value
End Functio

Public Function IndexOf(ByVal value As C3MenuItem) As Intege
Return Me.List.IndexOf(value
End Functio

Public Sub Remove(ByVal value As C3MenuItem
Me.List.Remove(value)
End Sub

Public Sub Insert(ByVal index As Integer, ByVal value As C3MenuItem)
Me.List.Insert(index, value)
End Sub

End Class

C3MenuItem Class:
(All properties in this class are one of the following types: String, Boolean, Color)

Public Class C3MenuItem

Public pOwningMenu As C3Menu

' MenuItem property storage:
Dim _align As String = ""
Dim _closeonclick As Boolean = True
Dim _color3dlow As Color = ColorTranslator.FromHtml("")
....
[/code]
 
J

Jim-M

One thing I've found is that collection properties need to be ReadOnly.
Try changing your property to

Public ReadOnly Property [MenuItems]() As C3MenuItemCollection
Get
If _menuitems Is Nothing Then _menuitems = New C3MenuItemCollection
Return _menuitems
End Get
End Property

Your code snippet included both ReadOnly as well as a Set & Get
accessor. This shouldn't compile...either lose the Set accessor or lose
the ReadOnly.

Todd Lucas said:
I'm having some weird things happen in design view while editing a
custom collection - I've been at this for about 4 weeks now, and have
tried all the different combinations of persistence settings
(DesignerSerializationVisibility, PersistenceMode, etc) there is, and
all to no avail! I'm hoping someone here can help ...
Environment: VS.NET 2003 v7.1.3088, Win2000 v5.00.2195 SP3, IE6 v6.0.2800.1106CO

The problem is one of collection item persistence. The problem can be
repeated by using the following steps:
1) create new webform, and drop C3Menu control on it from Toolbox.
2) click control to select it.
3) click ellipse button on the MenuItems property to edit collection
(via standard CollectionEditor).
4) add a new item, and click Ok button to save changes / close collection editor.
5) switch to HTML view - changes are persisted ok.
6) switch back to design view, and run the test project.
7) control appears fine on webform, with all items listed.
8) close webform to return to design view.
9) click control to select it.
10) click ellipse button on the MenuItems property to edit collection
(via standard CollectionEditor).
11) add a new item, and click Ok button to save changes / close collection editor.
12) switch to HTML view - changes are NOT persisted!

It gets even weirder, because if I repeat steps 9-12 a second time
(right after doing all 12) to add another new item, the previous item
AND the second new item are persisted!
If I remove the "SET" accessor on the MenuItems property in the C3Menu
class, a new problem is presented: "Design View: Error creating
control - '' could not be set on property MenuItems". This problem
occurs if I close the webform after adding items to the collection, and
try to reopen it. The application still runs ok, and the control is
presented properly on the webform at run time, but the designer
complains that the control cannot be created (above message) - I then
cannot access any properties for the control in design view, but can add
new items in the HTML view and they appear fine on the webform at run
time.
Any ideas? I would be happy to send the full source code to anyone
that wants to help. Any help would be appreciated.
Thanks - Todd

The Code (snippets):

Code:
C3Menu Class:

<DefaultEvent("ItemClick"), _
Description("Server Control - Menu Definition."), _
ParseChildren(True, "MenuItems"), PersistChildren(False), _
ToolboxData("<{0}:C3Menu runat=server></{0}:C3Menu>")> _
Public Class C3Menu : Inherits System.Web.UI.WebControls.WebControl
...
Dim _menuitems As New C3MenuItemCollection
...
<Category("Menu Properties"), NotifyParentProperty(True), _
[/QUOTE]
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
, _[QUOTE]
PersistenceMode(PersistenceMode.InnerDefaultProperty), _
Description("Collection of Menu Items this object will display.")> _
ReadOnly Property [MenuItems]() As C3MenuItemCollection
Get
Return _menuitems
End Get
' ** Note - SET causes control creation errors when the page is loaded!
Set(ByVal Value As C3MenuItemCollection)
If Not IsNothing(Value) Then _menuitems = Value
End Set
End Property
...

C3MenuItemCollection Class:

Public Class C3MenuItemCollection : Inherits System.Collections.CollectionBase

Public Sub New()
MyBase.New()
End Sub

Default Public Property Item(ByVal index As Integer) As C3MenuItem
Get
Return CType(Me.List(index), C3MenuItem)
End Get
Set(ByVal Value As C3MenuItem)
Me.List(index) = Value
End Set
End Property

Public Function Add(ByVal value As C3MenuItem) As Integer
Return Me.List.Add(value)
End Function

Public Function Contains(ByVal value As C3MenuItem) As Boolean
Return Me.List.Contains(value)
End Function

Public Function IndexOf(ByVal value As C3MenuItem) As Integer
Return Me.List.IndexOf(value)
End Function

Public Sub Remove(ByVal value As C3MenuItem)
Me.List.Remove(value)
End Sub

Public Sub Insert(ByVal index As Integer, ByVal value As C3MenuItem)
Me.List.Insert(index, value)
End Sub

End Class

C3MenuItem Class:
(All properties in this class are one of the following types:  String, Boolean, Color)

Public Class C3MenuItem

Public pOwningMenu As C3Menu

' MenuItem property storage:
Dim _align As String = ""
Dim _closeonclick As Boolean = True
Dim _color3dlow As Color = ColorTranslator.FromHtml("")
...
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top