Groups | Blog | Home
all groups > asp.net building controls > august 2003 >

asp.net building controls : Inheriting from System.Web.UI.WebControls.Table


Jimmy [Used-Disks]
8/14/2003 2:24:10 PM
I am trying to create an ASP.NET control by inheriting from Table. I would
like to stop the Rows property from being displayed/persisted at
design-time, plus I would like to have new properties I have introduced be
persisted as nested tags within my controls tag in the ASP.NET page. To do
this I have overridden the Rows property as follows:

[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
PersistenceMode(PersistenceMode.InnerProperty)]
public override TableRowCollection Rows{
get{
return base.Rows;
}
}

This succesfully hides the Rows property from the properties window in the
IDE, however when other properties are persisted within the tags, it throws
an exception (at both design and run time):
"System.Web.UI.WebControls.TableRowCollection must have items of type
'System.Web.UI.WebControls.TableRow'. 'MyCustomProperty' is of type
'System.Web.UI.HtmlControls.HtmlGenericControl'."

I have also tried using "new" instead of "override" to re-declare the Rows
property and have gotten the same results.

My question is, how do I get around this? I do *not* want a
DefaultInnerProperty for my control because I am trying to generate all the
TableRows programatically and need to persist other properties as Inner
Properties. Is there any way around this, such as an attribute I can apply
to the Rows property or to my control?

Thanks -

--
-Jimmy
Used-Disks:
http://www.used-disks.com/

Jimmy [Used-Disks]
8/14/2003 2:32:03 PM
[quoted text, click to view]

Found it! The answer is to apply the ParseChildren(true) and
PersistChildren(false) attributes to the control class because the Table
class had overridden the WebControls default implementation which is the
behavior we desired.

Thanks for reading :).

--
-Jimmy
Used-Disks:
http://www.used-disks.com/

AddThis Social Bookmark Button