WebControl with derived propertied is not saving partial property in the HTML

U

Undecided

Weird, here is a code example:
If you make a brand new web control that has a property of type ITest2
and you create Test2 in there. Lets say I set both properties of Test2
to some string. When I flip to the HTML page I only see the property
DestObject which is defined in ITest2 but I don't see the property
from ITest1. So, when I close and reopen the form my
ITest1.SourceObject property is blank again.
Any ideas?

Thanks

CZ

public interface ITest1
{
string SourceObject
{
get; set;
}
}

public interface ITest2: ITest1
{
string DestObject
{
get; set;
}
}

[SerializableAttribute]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Test1: Itest1
{
protected string _SourceObject="";
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[NotifyParentProperty(true)]
[DefaultValue("")]
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public string SourceObject
{
get {return _SourceObject;}
set {_SourceObject = value; }
}
}

[SerializableAttribute]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Test2: Test1, ITest2
{
protected string _DestObject="";
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[NotifyParentProperty(true)]
[DefaultValue("")]
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public string DestObject
{
get {return _DestObject;}
set {_DestObject = value; }
}
}

//======================================
// WEB CONTROL
//======================================

public class TestControl: WebControl
{
protected ITest2 _Test2;

[Browsable(true)]
[Category("Data")]
[DesignerSerializationVisibility
DesignerSerializationVisibility.Content)]
[NotifyParentProperty(true)]
public ITest2 MyTest2 {
get {
if (_Test2 == null )
{
_Test2 = new Test2();
}
return this._Test2;
}
}
}
 
U

Undecided

Basically, properties that are based on derived interfaces only
serialize the latest interface properties and none of the ancestor
properties. I verified this by not inheriting from a base interface.
Instead I added all the ancestor properties to the derived interface
and they all serialized properly!
Amazing, I hope it's something simple and not a bug.

CZ
 

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,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top