Custom Controls and Type Properties not saving in html tag

L

Luciano Criscola

Hi all,

I am building a custom control and I add one primitive type (MyProperty1)
and one MyClass type (MyProperty2) as public properties

I had to make MyClass implement the IComponent interface so it would show
properly in the properties window ( It show the name of the property and a +
sign with al the properties of MyClass as children)

When a make some change in the properties window to MyProperty1, the new
values are reflected int the HTML view MyProperty1="MyValue" but when I do
the same with the object property instead of seeing
MyProperty2-MyProperty3="MyValue" I see nothing. But if I add manually
MyProperty2-MyProperty3="MyValue" in the HTML view, I see the change in the
property window.

Did I make my self clear...??
Well thanks anyway.

Here is the code

//--- B E G I
N---------------------------------------------------------------------------
---------------------------------
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace MyNameSpace
{
public class MyClass :IComponent
{
private string myProperty3= "";
private string myProperty4= "";

public string MyProperty3
{
get {return myProperty3;}
set {myProperty3=value;}
}
public string MyProperty4
{
get {return myProperty4;}
set {myProperty4=value;}
}

#region IComponent Members

public event System.EventHandler Disposed;

public ISite Site
{
get
{
// TODO: Add MyClass.Site getter implementation
return null;
}
set
{
// TODO: Add MyClass.Site setter implementation
}
}

#endregion

#region IDisposable Members

public void Dispose()
{
// TODO: Add MyClass.Dispose implementation
}

#endregion
}


public class MyCustomControl :DataGrid
{
private string myProperty1="";
private MyClass myProperty2= new MyClass();

public string MyProperty1
{
get {return myProperty1;}
set {myProperty1=value;}
}

public MyClass MyProperty2
{
get { return myProperty2 ;}
set { myProperty2=value;}
}
}
}
//----E N
D---------------------------------------------------------------------------
 
T

Teemu Keiski

In normal scenario if you want your control to be visible in the editor and
the HTML persisting etc to work like it is intended for controls, your
control would need to derive from System.Web.UI.Control or
System.Web.UI.WebControls.WebControl

About complex properties:
-They need to be read-only and instantiated when the property is first time
accessed (lazy instantiation)
-Have NotifyParentProperty(true) attribute applied
-Have
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
attribute applied

--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com
 
L

Luciano Criscola

Teemu ,
DesignerSerializationVisibility(DesignerSerializationVisibility.Content) was
the key to make it work.

Thank you so much.

Luciano.
 

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

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top