Persisting custom dictionary property

Discussion in 'ASP .Net Building Controls' started by Nels P. Olsen, Aug 2, 2006.

  1. I have a custom ASP control (an extension of DataSourceControl) that contains
    a custom property, which contains a custom dictionary property. I can't get
    the custom dictionary property to persist correctly from my custom designer.
    The code looks like this:

    [Designer(typeof(MyCustomControlDesignerType)]
    [ParseChildren(true)]
    [PersistChildren(false)]
    [Serializable]
    public class MyCustomControlType : System.Web.UI.DataSourceControl
    {

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public MyCustomPropertyType CustomProperty {get { ... } set {...}}
    }

    public class MyCustomControlDesignerType :
    System.Web.UI.Design.DataSourceDesigner
    {
    ...
    }

    [ParseChildren(true)]
    [PersistChildren(false)]
    [Serializable]
    public MyCustomPropertyType
    {
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [PersistenceMode(PersistenceMode.Attribute)]
    public string SomeShortTextProperty {get {...} set {...}}

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public string SomeLongTextProperty {get {...} set {...}}

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public MyCustomDictionaryType CustomDictionaryProperty {get {...} set
    {...}}
    }

    [Serializable]
    public MyCustomDictionaryType : IDictionary, ...
    {
    public MyCustomDictionaryValueType this[string key] {get {...} set {...}}

    // Implementation of IDictionary members
    // enforces dictionary values of type MyCustomDictionaryValueType
    // MyCustomDictionaryValueType.Name is automatically used as the key
    }

    [ParseChildren(true)]
    [PersistChildren(false)]
    [Serializable]
    public MyCustomDictionaryValueType
    {
    // The Name property serves as the dictionary key
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [PersistenceMode(PersistenceMode.Attribute)]
    public string Name {get {...} set {...}}

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [PersistenceMode(PersistenceMode.Attribute)]
    public Type Type {get {...} {set {...}}
    }

    When I save changes to an instance of my control in my designer, the
    dictionary entries are persisted in the ASP markup like this:

    <myNamespace:MyCustomControlType>
    <CustomProperty SomeShortTextProperty="...">
    <SomeLongTextProperty>
    ...
    </SomeLongTextProperty>
    <CustomDictionaryProperty>
    <dictionaryentry key="theKey" value="theValueToString">
    ...
    </CustomDictionaryProperty>
    </CustomProperty>
    </myNamespace:MyCustomControlType>

    I haven't been able to figure out a way to control the persisted ASP markup
    of the dictionary entries. I've tried all kinds of things -- implementing
    IXmlSerializable in my custom dictionary class, decorating my custom
    dictionary value class with a custom type converter, etc. Nothing I do has
    any effect.

    How can I get the persisted ASP markup to look like this, which I can
    deserialize:

    <CustomDictionaryProperty>
    <CustomDictionaryValue Name="theKey" Type="theAssemblyQualifiedName">
    ...
    </CustomDictionaryProperty>

    instead of this, which I can't deserialize:

    <CustomDictionaryProperty>
    <dictionaryentry key="theKey"
    value="MyNamespace.MyCustomDictionaryValueType">
    ...
    </CustomDictionaryProperty>
     
    Nels P. Olsen, Aug 2, 2006
    #1
    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. Ahmet Gunes

    Persisting a property (e.g. TabIndex) in a control's Tag on creation

    Ahmet Gunes, Jun 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    160
    Ahmet Gunes
    Jun 14, 2004
  2. Persisting a collection property in a custom datagrid

    , Dec 5, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    113
  3. Jeremy Chapman

    Need help persisting arraylist property.

    Jeremy Chapman, Feb 18, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    161
    Jeremy Chapman
    Feb 18, 2006
  4. JesperA

    Problem persisting asp.net 2.0 property in design-time

    JesperA, Oct 17, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    139
    Brennan Stehling
    Oct 18, 2006
  5. schmurgon
    Replies:
    0
    Views:
    162
    schmurgon
    Dec 16, 2006
Loading...

Share This Page