C
Chris
I've created some components that rennder themselves as table rows.
They do not show up in the designer if I put them inside a table tag
even if I give them a System.Web.UI.Design.ControlDesigner whose
GetDesignTimeHtml returns <TR>contents</TR>.
So I've created a special table control that can have them as
children. This renders as a DIV at design time and the TRs render
themselves each as a Table.
They both render fine on their own but when I nest the TR in the Table
it shows the contents of the TR as if the ControlDesigner for the TR
is being ignored and the Render method is called ( 'foo' shows at
design time instead of 'bar' ).
It only works at all if I add [ParseChildren(false)] to the Table
control, otherwise it tells me that it does not have a property of
type cc1:HTMLTableRow.
How can I add this property given that a Table can have multiple TRs
and that cc1 is just one possible tag prefix.
Or how do I get the TR ControlDesigner to be called from the
TableDesigner's GetDesignTimeHtml()?
I've tried creating an instance of MyHTMLTableRowDesigner in
MyHTMLTableDesigner but it's Control property is readonly.
At the moment I've resorted to copying the GetDesignTimeHtml into the
TR component itself as this can be called from the Controls of the
Table Component in it's designer but it's not very satisfactory.
////////////////////////// TR Control /////////////////////////
[Designer(typeof(TBP.WebControls.MyHTMLTableRowDesigner)),
ToolboxData("<{0}:MyHTMLTableRow runat=server></0}:MyHTMLTableRow>")]
public class MyHTMLTableRow : System.Web.UI.WebControls.WebControl
{
public HTMLTableRow()
{
}
protected override void Render(HtmlTextWriter output)
{
output.Write( @"
<TR>
<TD style='width:200px;> foo </TD>
</TR") ;
}
}
public class MyHTMLTableRowDesigner :
System.Web.UI.Design.ControlDesigner
{
public override string GetDesignTimeHtml()
{
return "<TABLE border='1'><TR><TD> bar </TD><TD></TABLE>" ;
}
}
////////////////////////// TABLE Control ///////////////////////////
[ParseChildren(false)]
[Designer(typeof(TBP.WebControls.MyHTMLTableDesigner)),
ToolboxData("<{0}:MyHTMLTable runat=server></{0}:MyHTMLTable>")]
public class MyHTMLTable : System.Web.UI.WebControls.WebControl
{
public MyHTMLTable()
{
}
protected override void AddParsedSubObject(object obj)
{
// ignore all child controls except TRs
MyHTMLTableRow tr = obj as MyHTMLTableRow;
if ( null != tr )
this.Controls.Add(tr);
}
protected override void Render(HtmlTextWriter output)
{
output.Write( @"
<TABLE class='MyTable'><TBODY> " ) ;
foreach ( Control ctl in this.Controls )
ctl.RenderControl(output);
output.Write( @"
</TBODY></TABLE>" ) ;
}
}
public class MyHTMLTableDesigner :
System.Web.UI.Design.ControlDesigner
{
public override string GetDesignTimeHtml()
{
string html = "<DIV style='border: 1px dotted black'>" ;
html += base.GetDesignTimeHtml() ;
html += "</DIV>" ;
return html ;
}
}
They do not show up in the designer if I put them inside a table tag
even if I give them a System.Web.UI.Design.ControlDesigner whose
GetDesignTimeHtml returns <TR>contents</TR>.
So I've created a special table control that can have them as
children. This renders as a DIV at design time and the TRs render
themselves each as a Table.
They both render fine on their own but when I nest the TR in the Table
it shows the contents of the TR as if the ControlDesigner for the TR
is being ignored and the Render method is called ( 'foo' shows at
design time instead of 'bar' ).
It only works at all if I add [ParseChildren(false)] to the Table
control, otherwise it tells me that it does not have a property of
type cc1:HTMLTableRow.
How can I add this property given that a Table can have multiple TRs
and that cc1 is just one possible tag prefix.
Or how do I get the TR ControlDesigner to be called from the
TableDesigner's GetDesignTimeHtml()?
I've tried creating an instance of MyHTMLTableRowDesigner in
MyHTMLTableDesigner but it's Control property is readonly.
At the moment I've resorted to copying the GetDesignTimeHtml into the
TR component itself as this can be called from the Controls of the
Table Component in it's designer but it's not very satisfactory.
////////////////////////// TR Control /////////////////////////
[Designer(typeof(TBP.WebControls.MyHTMLTableRowDesigner)),
ToolboxData("<{0}:MyHTMLTableRow runat=server></0}:MyHTMLTableRow>")]
public class MyHTMLTableRow : System.Web.UI.WebControls.WebControl
{
public HTMLTableRow()
{
}
protected override void Render(HtmlTextWriter output)
{
output.Write( @"
<TR>
<TD style='width:200px;> foo </TD>
</TR") ;
}
}
public class MyHTMLTableRowDesigner :
System.Web.UI.Design.ControlDesigner
{
public override string GetDesignTimeHtml()
{
return "<TABLE border='1'><TR><TD> bar </TD><TD></TABLE>" ;
}
}
////////////////////////// TABLE Control ///////////////////////////
[ParseChildren(false)]
[Designer(typeof(TBP.WebControls.MyHTMLTableDesigner)),
ToolboxData("<{0}:MyHTMLTable runat=server></{0}:MyHTMLTable>")]
public class MyHTMLTable : System.Web.UI.WebControls.WebControl
{
public MyHTMLTable()
{
}
protected override void AddParsedSubObject(object obj)
{
// ignore all child controls except TRs
MyHTMLTableRow tr = obj as MyHTMLTableRow;
if ( null != tr )
this.Controls.Add(tr);
}
protected override void Render(HtmlTextWriter output)
{
output.Write( @"
<TABLE class='MyTable'><TBODY> " ) ;
foreach ( Control ctl in this.Controls )
ctl.RenderControl(output);
output.Write( @"
</TBODY></TABLE>" ) ;
}
}
public class MyHTMLTableDesigner :
System.Web.UI.Design.ControlDesigner
{
public override string GetDesignTimeHtml()
{
string html = "<DIV style='border: 1px dotted black'>" ;
html += base.GetDesignTimeHtml() ;
html += "</DIV>" ;
return html ;
}
}