CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 10/24/2005 11:34:43 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 6 Views: 40 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
7 Items, 1 Pages 1 |< << Go >> >|
BoulderBum
Asp.Net User
Serializing a Custom Collection in the Designer10/24/2005 11:34:43 PM

0/0

I have a custom object MyObject that I want to serialize in a collection in my server control at design-time like this:

<cc1:...>
        <MyObject property="blah"/>
        <MyObject property="blah blah"/>
</cc1:...>

I figured out how to do it with an ArrayList (by setting the inner-default property, parsechildren to true, etc.), but I'd like to do it with a List<MyObject> generic. Anyone know where to start (if I have a class that inherits from List<MyObject>)?
BoulderBum
Asp.Net User
Re: Serializing a Custom Collection in the Designer10/26/2005 9:05:18 PM

0/0

Okay, I guess what I really want is whatever the heck is serializing everything to do so like this:

<cc1:...>
   <cc1:MyObject...> <!-- I'm not currently getting the namespace cc1:... -->
</cc1:...>

but since the serializer isn't persisting MyObject properly, it simply sees the inner element as an HtmlGenericControl or whatever it's called.

Anyone know what I might be missing?

BoulderBum
Asp.Net User
Re: Serializing a Custom Collection in the Designer10/27/2005 12:26:56 AM

0/0

Okay, after two full days of trying to track the problem down, I discovered the issues was that the item being contained had a different namespace than the control housing it. Angry [:@] Unfortunately the server control can't resolve or register the namespace of the inner items,  The weird part is that there doesn't appear to be any documentation on the phenomenon, but I'm surprised the issue hasn't come up more in the past!

Actually, logically speaking it seems like a ControlBuilder should be able to take care of that, but it didn't seem to work.

Is this a bug, or am I just being silly (again)?

dannychen
Asp.Net User
Re: Serializing a Custom Collection in the Designer11/4/2005 6:34:33 PM

0/0

In order for intellisense of collection items to be availible, the object type must exist in the same namespace as the control.  So, while you can create a collection of Menu Items in your custom control and declaratively instantiate them, you won't get intellisense for the items unless you create your own in the namespace of your custom control.

Did you have any trouble using Generics for your item collection?  I found it was very straight forward.  Here's an example I put together.

Namespace mine

    <ParseChildren(True, "items")> _
    Public Class Class1
        Inherits WebControl

        Private _items As List(Of Item)

        <PersistenceMode(PersistenceMode.InnerDefaultProperty)> _
        Public Property items() As List(Of Item)
            Get
                Return _items
            End Get
            Set(ByVal value As List(Of Item))
                _items = value
            End Set
        End Property

        Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
            For Each i As Item In items
                writer.WriteLine(i.Value)
            Next
        End Sub

    End Class

    Public Class Item
        Private v As String
        Public Property Value() As String
            Get
                If v Is Nothing Then
                    Return String.Empty
                End If
                Return v
            End Get
            Set(ByVal value As String)
                v = value
            End Set
        End Property
    End Class
End Namespace

--
Danny


disclaimer: Information provided is 'as is' and conveys no warranties or guarantees.
BoulderBum
Asp.Net User
Re: Serializing a Custom Collection in the Designer11/4/2005 7:48:20 PM

0/0

Well, like I was saying, the heart of the issue was that I didn't realize the items of a contained collection had to share a similar namespace as the parent control for proper serialization/deserialization in the designer (intellisense behind the scenes was never an issue because I could easily add reference a dissimilar namespace). After figuring that out, it was trivial implementing the child list property as a generic type. In my case my item was an IStateManager and I created my own Generic collection class (also an IStateManager) for efficient interaction with ViewState, but I digress.

Anyway, the thing you might be able to help me with is getting around the namespace requirement (which seems silly to me). From what I understand of a ControlBuilder, it seems that I should be able to use one to parse all the inner-elements however I want to (no matter what namespace they came from), but I kept running into a problem where it tried to parse the inner elements as HtmlGenericControls (which caused a design-time error the control barfed on).

Basically, if given this arrangement:

FirstNamespace.MyControl
SecondNamespace.MyCollection
ThirdNamespace.MyItem

How do you set things up so that the control can properly parse the children?
SimonCal
Asp.Net User
Re: Serializing a Custom Collection in the Designer11/8/2005 10:15:21 PM

0/0

Did You try set registering a tagprefix for the collection in the control's controldesigner? For example, in the ControlDesigner.Initialize override, calling on WebFormsRootDesigner.References.RegistertagPrefix?
Simon
This posting is provided "AS IS" with no warranties, and confers no rights.
BoulderBum
Asp.Net User
Re: Serializing a Custom Collection in the Designer11/15/2005 6:41:16 AM

0/0

I haven't tried that yet. I certainly will, however and I'll try to report back on how it worked out.
7 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Developing .NET Custom Controls and Designers Using Visual Basic .NET Authors: James Henry, Pages: 600, Published: 2005
ASP.NET 2.0 Website Programming: Problem-design-solution Authors: Marco Bellinaso, Pages: 576, Published: 2006
.NET Windows Forms Custom Controls: Forms Custom Controls Authors: Richard L. Weeks, Pages: 288, Published: 2002
Pro ASP.NET 2.0 in C# 2005: Create Next-generation Web Applications with the Latest Version of Microsoft's Revolutionary Technology Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1426, Published: 2006
Professional Java, JDK: Jdk Authors: W. Clay Richardson, Donald Avondolio, Joe Vitale, Scot Schrager, Mark W. Mitchell, Jeff Scanlon, Pages: 712, Published: 2005
Windows Forms Programming in C# Authors: Chris Sells, Pages: 681, Published: 2004
Pro .NET 2.0 Windows Forms and Custom Controls in C#: From Professional to Expert Authors: Matthew MacDonald, Pages: 1037, Published: 2005
Pro .NET 2.0 Windows Forms and Custom Controls in VB 2005 Authors: Matthew MacDonald, Pages: 1036, Published: 2006
Pro WF: Windows Workflow in .NET 3.0 Authors: Bruce Bukovics, Pages: 709, Published: 2007
User Interfaces in C#: Windows Forms and Custom Controls Authors: Matthew MacDonald, Pages: 586, Published: 2002

Web:
How to serialize a custom collection in a custom control Maybe there is a way to tell the Visual Studio IDE respectivly the Form designer , to serialize my custom collection without using resources. ...
XmlSerializer and Custom Collections - .NET XML I've discovered that when serializing a custom collection (a class that .... Ross Donald Rad Software Free Regular Expression Designer @ ...
Re: Serializing Forms and Controls on a Custom Forms Designer designer host technologies, ... had issues with serialization, ... custom collection Editor will not help in that case and a custom designer is . ...
XML Serialization in the .NET Framework This behavior is by design. The only work around is to re-factor the custom collection into two classes, one of which exposes the properties including one ...
CodeProject: Editing Multiple Types of Objects with Collection ... Explains use of Custom Collection Editors to create objects for a component during design ... The created objects during design time must be serialized. ...
Design time serialization in C# - Stack Overflow The component I was implementing a custom collection (inherited from ... Browse other questions tagged c# .net serialization design or ask your own question ...
XML serialization of custom collection class in VB - .NET XML XML serialization of custom collection class in VB. ... implement. -- Ross Donald Rad Software Free Regular Expression Designer @ ...
ploeh blog : Serializing Read-Only Collections to Code Feb 18, 2006 ... Using a custom collection class is obviously a limitation in usability ... Design.Serialization.CodeDomSerializer. To make it serialize the ...
Walkthrough: Serializing Collections of Standard Types with the ... Once you know how to serialize a collection of standard types, consider integrating your custom controls more deeply into the design-time environment. ...
CodeIdol - Thinking about Essential Windows Workflow Foundation ... You are free to develop an entirely custom serialization capability for your .... Collection Serialization. Designer serializer components can establish and ...

Videos:
Using Static Analysis For Software Defect Detection Google TechTalks July 6, 2006 William Pugh ABSTRACT I'll talk about some of my experience in using and expanding static analysis tools for defect d...




Search This Site:










cool ui: how do they do it? entforms

does asp.net config tool work with custom membershipuser???

server control viewstate help

trying to setup security

sql server does not exist or access denied

dnn support

web conf error

#include - why or why not?

develop locally, then publish to remote server

help with stats

very strange access 2000 question

vs2005 solution will only add project from one location

access hashtable value?

installing dnn with sql server 2000

login control issue

announcing: portal mapper -- share your user base across mutli-portal installations

windows authentification setup help

can't create a module for 3.0.9? many errors on build?

login view control??

startup page?

why is my master page firing page_load twice?

object reference not set to an instance of an object.

formsauthentication timeout

resizing images from url

session.isnewsession question

membership.isonline() and formsauthentication.signout()

i had the same problem.

error when moving portal to private status

httpcookie - read / write

session state in vs 2005

 
All Times Are GMT