WebControl Designer Problem using Custom Collection

  • Thread starter Todd Lucas via .NET 247
  • Start date
T

Todd Lucas via .NET 247

I'm having some weird things happen in design view while editinga custom collection - I've been at this for about 4 weeks now,and have tried all the different combinations of persistencesettings (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, IE6v6.0.2800.1106CO

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

1) create new webform, and drop C3Menu control on it fromToolbox.
2) click control to select it.
3) click ellipse button on the MenuItems property to editcollection (via standard CollectionEditor).
4) add a new item, and click Ok button to save changes / closecollection 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 editcollection (via standard CollectionEditor).
11) add a new item, and click Ok button to save changes / closecollection editor.
12) switch to HTML view - changes are NOT persisted!

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

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

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

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 : InheritsSystem.Web.UI.WebControls.WebControl
...
Dim _menuitems As New C3MenuItemCollection
...
		<Category("Menu Properties"), NotifyParentProperty(True), _
		DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
		PersistenceMode(PersistenceMode.InnerDefaultProperty), _
		Description("Collection of Menu Items this object willdisplay.")> _
		ReadOnly Property [MenuItems]() As C3MenuItemCollection
			Get
				Return _menuitems
			End Get
			'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) AsC3MenuItem
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) AsInteger
Return Me.List.Add(value)
End Function

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

Public Function IndexOf(ByVal value As C3MenuItem) AsInteger
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 AsC3MenuItem)
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("")
...
 
J

Jiho Han

From what I can see, I don't know if that's the problem or not, your
collection property should be written like this:

(sorrry I'm a c# guy)

private C3MenuItemCollection _menuItems;
// your attributes for this property seems correct.
public C3MenuItemCollection MenuItems
{
get
{
if (_menuItems == null)
_menuItems = new C3MenuItemCollection(); // or any other variant
you use to create this collection.
return _menuItems;
}
}

You shouldn't have a setter because... I can't explain it but it gets messy
if you do. If someone can elaborate, please feel free as I would appreciate
a clear explanation as well.

As for your C3MenuItem, you should also have NotifyParentProperty(true) for
each of your public properties as well so that the changes get properly
propagated to the collection, etc.

I'm sorry I couldn't be of more help.
Good luck!

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.

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), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
PersistenceMode(PersistenceMode.InnerDefaultProperty), _
Description("Collection of Menu Items this object will display.")> _
ReadOnly Property [MenuItems]() As C3MenuItemCollection
Get
Return _menuitems
End Get
'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("")
....
 
B

BMukes

Try this web site
http://users.adelphia.net/~brianpclab/ServerControlCollectionIssues.htm

Jiho Han said:
From what I can see, I don't know if that's the problem or not, your
collection property should be written like this:

(sorrry I'm a c# guy)

private C3MenuItemCollection _menuItems;
// your attributes for this property seems correct.
public C3MenuItemCollection MenuItems
{
get
{
if (_menuItems == null)
_menuItems = new C3MenuItemCollection(); // or any other variant
you use to create this collection.
return _menuItems;
}
}

You shouldn't have a setter because... I can't explain it but it gets messy
if you do. If someone can elaborate, please feel free as I would appreciate
a clear explanation as well.

As for your C3MenuItem, you should also have NotifyParentProperty(true) for
each of your public properties as well so that the changes get properly
propagated to the collection, etc.

I'm sorry I couldn't be of more help.
Good luck!

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.

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), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
PersistenceMode(PersistenceMode.InnerDefaultProperty), _
Description("Collection of Menu Items this object will display.")> _
ReadOnly Property [MenuItems]() As C3MenuItemCollection
Get
Return _menuitems
End Get
'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

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top