[Need Expert] Big design time problem

  • Thread starter Thread starter Loïc
  • Start date Start date
L

Loïc

Hello,

I have created a simple webcontrol named MyControl tahat contains one single
property. The property name is Columns , his type is ColumnCollection (
inherits from CollectionBase). this property contains an elements list and
the type of these elements is Column.

On a WebForm (in design mode), i insert my MyControl webcontrol . Je fill
in his Columns property ( it inherits from CollectionBase type so the
collection editor is opened ). Then i switch to Html mode to see the
generated Xml code :

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="Xes_Web_Controls.WebForm1" %>
<%@ Register TagPrefix="cc1" Namespace="Controls" Assembly="Controls" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<cc1:mycontrol id="MyControl9" style="Z-INDEX: 101; LEFT: 336px;
POSITION: absolute; TOP: 168px" runat="server" Width="464px">
<Columns>
<cc1:Column Type="string" Name="prenom"></cc1:Column>
<cc1:Column Type="string" Name="nom"></cc1:Column>
</Columns>
</cc1:mycontrol>
</form>
</body>
</HTML>

At this step there is no problem. Buyt then i close the file which contains
my webform, then i re-open the file. I switch to design mode and there is an
error on my control ('' could not be set on property 'Columns' ).
I do not understand this error and do no know resolve this error.

Does anybody help me

Thanks

Loïc

PS : at bottom, we can find my sources
[MyControl.cs]
using System;
using System.ComponentModel ;
using System.Web.UI ;
using System.Web.UI.WebControls ;

namespace Controls
{
public class MyControl : WebControl
{

private ColumnCollection m_columns ;
public MyControl()
{
m_columns = new ColumnCollection() ;
}
[
PersistenceMode(PersistenceMode.InnerProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true)
]
public ColumnCollection Columns
{
get { return m_columns ; }
set { m_columns = value ; }
}
}
}

[ColumnCollection.cs]
namespace Controls
{
using System;
using System.Collections ;
using System.ComponentModel ;
using System.Web.UI ;

public class ColumnCollection : CollectionBase
{
public ColumnCollection() : base( )
{

}
public void AddColumn( Column _col )
{
List.Add( _col ) ;
}
[NotifyParentProperty(true)]
public Column this[int index]
{
get { return List[index] as Column ; }
set { List[index] = value ; }
}
}
}

[Column.cs]
namespace Controls
{
using System;
public class Column
{
private string m_name ;
private string m_type ;
public Column()
{

}
public string Name
{
get { return m_name ; }
set { m_name = value ; }
}
public string Type
{
set { m_type = value ; }
get { return m_type ; }
}
}
}
 
I think you are missing inner default property persistence.
To enable inner default property persistence, you must mark your control
with the following variation of the ParseChildrenAttribute, where the
second argument of the attribute is the name of the inner default
property:

[
ParseChildren(true, "Columns")
]
public class MyControl : WebControl { ... }


Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
 
Hi,

I can try, what's the error.

if you can put your hand on that book [1], I think it will solve all of
your problems. what you're after isn't trivial task.

[1] Developing Microsoft ASP.NET Server Controls and Components
By Nikhil Kothari, Vandana Datje

Publisher : Microsoft Press
Pub Date : September 28, 2002
ISBN : 0-7356-1582-9


Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
 
Back
Top