WebControl Designer Problem using Custom Collection

Discussion in 'ASP .Net Building Controls' started by Todd Lucas via .NET 247, May 13, 2004.

  1. 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("")
    ...
    
    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>YhAbs2Qc3EKYGXPb6StBKQ==</Id>
    Todd Lucas via .NET 247, May 13, 2004
    #1
    1. Advertising

  2. Todd Lucas via .NET 247

    Jiho Han Guest

    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!

    "Todd Lucas via .NET 247" <> wrote in message
    news:...
    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("")
    ....
    
    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>YhAbs2Qc3EKYGXPb6StBKQ==</Id>
    Jiho Han, May 13, 2004
    #2
    1. Advertising

  3. Todd Lucas via .NET 247

    BMukes Guest

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

    "Jiho Han" <> wrote in message
    news:...
    > 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!
    >
    > "Todd Lucas via .NET 247" <> wrote in message
    > news:...
    > 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),[/color]
    _[color=blue]
    > 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[/color]
    C3MenuItem)[color=blue]
    >             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("")
    > ...
    > 
    >
    > -----------------------
    > Posted by a user from .NET 247 (http://www.dotnet247.com/)
    >
    > <Id>YhAbs2Qc3EKYGXPb6StBKQ==</Id>
    >
    >
    BMukes, May 28, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Øyvind Isaksen
    Replies:
    1
    Views:
    929
    Øyvind Isaksen
    May 18, 2007
  2. Fabricio

    Custom webcontrol that references another webcontrol

    Fabricio, Sep 21, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    161
    Fabricio
    Sep 21, 2005
  3. KK

    Webcontrol custom designer

    KK, Nov 12, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    115
    Steve C. Orr [MVP, MCSD]
    Nov 14, 2005
  4. Replies:
    1
    Views:
    272
    Tim Dot NoSpam
    May 19, 2006
  5. kl

    nested webcontrol collection designer tag error

    kl, Jan 23, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    114
Loading...

Share This Page