Ask a Question related to ASP.NET Building Controls, Design and Development.
-
jb_in_marietta@yahoo.com #1
Using Table control in a custom composite control. Control does not render properly in design time.
All,
I have written a very simple custom composite control that includes a
control of type System.Web.UI.WebControls.Table.
The control renders fine in run time, but for some reason, it does not
render properly in design time.
In design time it renders something like this:
[TestTableControl "TestTableControl1"]
Could someone please explain why this control does not render in
design time.
(complete code is included below)
Thanks in advance!!!
--Jonathan
------------------------------------------------------------------------------
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections;
namespace StyleLibFunctions
{
#region TestTableControl
[ToolboxData("<{0}:TestTableControl
runat=server></{0}:TestTableControl>")]
public class TestTableControl: WebControl
{
#region Variable Declaration
private Table _table;
private TableRow _tr;
private TableCell _td;
#endregion Variable Declaration
#region Overridden Properties
public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.Controls;
}
}
#endregion Overridden Properties
#region Overridden Methods
protected override void CreateChildControls ()
{
//clear controls
Controls.Clear();
//Create a Table object
_table = new Table();
_tr = new TableRow();
_td = new TableCell();
_td.Controls.Add(new LiteralControl("Cell Content"));
_tr.Cells.Add(_td);
_table.Rows.Add(_tr);
//add table to control tree
Controls.Add (_table);
}
protected override void Render(HtmlTextWriter writer)
{
_table.RenderControl(writer);
}
#endregion Overridden Methods
}
#endregion
}
jb_in_marietta@yahoo.com Guest
-
Custom control renders table but doesn't resize at design time.
Hi all, I have a control, that basically is my own version of the datagrid, except that is renderers purely readonly tabular information. When... -
custom control (with collection) do not render at Design time
Hello, I built a custom control... Everithing is working fine... EXCEPT... ;-) When I first place the control on the webform at design time it... -
Possible to create a composite control that has a child control that is a validator that validates the composite control itself?
I am attempting to create a composite control which has a label, followed by an optional error message, followed by two text boxes. I have... -
q: 'composite' control: works fine, but no children @ design time ?
Hi All ! I have my control, which populates inner ControlCollection via custom control builder and AddParsedSubObject function. Everything works... -
Composite Control design time behavior
I have created a composite control that combines a Label and a Textbox, where the label appears immediately above the textbox. This seems to work... -
jb_in_marietta@yahoo.com #2
Using Table control in a custom composite control. Control does not render properly in design time.
All,
I have written a very simple custom composite control that includes a
control of type System.Web.UI.WebControls.Table.
The control renders fine in run time, but for some reason, it does not
render properly in design time.
In design time it renders something like this:
[TestTableControl "TestTableControl1"]
Could someone please explain why this control does not render in
design time.
(complete code is included below)
Thanks in advance!!!
--Jonathan
------------------------------------------------------------------------------
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections;
namespace StyleLibFunctions
{
#region TestTableControl
[ToolboxData("<{0}:TestTableControl
runat=server></{0}:TestTableControl>")]
public class TestTableControl: WebControl
{
#region Variable Declaration
private Table _table;
private TableRow _tr;
private TableCell _td;
#endregion Variable Declaration
#region Overridden Properties
public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.Controls;
}
}
#endregion Overridden Properties
#region Overridden Methods
protected override void CreateChildControls ()
{
//clear controls
Controls.Clear();
//Create a Table object
_table = new Table();
_tr = new TableRow();
_td = new TableCell();
_td.Controls.Add(new LiteralControl("Cell Content"));
_tr.Cells.Add(_td);
_table.Rows.Add(_tr);
//add table to control tree
Controls.Add (_table);
}
protected override void Render(HtmlTextWriter writer)
{
_table.RenderControl(writer);
}
#endregion Overridden Methods
}
#endregion
}
jb_in_marietta@yahoo.com Guest
-
Teemu Keiski #3
Re: Using Table control in a custom composite control. Control does not render properly in design time.
Hi,
you should implement composite control designer for the control and also
generally implement INamingCotainer interface in the control.
About designer implementation:
a) Override Controls accessor to call EnsureChildControls before returning
base class implementation (You have done this already)
b) Write the designer and apply it for the control. Base logic is to call
Control's (it is Component for the designer) Controls accessor to make sure
child controls are created at the time when Control is rendered. This is
done in overridden GetDesignTimeHtml method. In overridden Initialize method
we just check that Control fulfills certain requirements. (You can also make
the designer general by removing type checkings)
Example:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections;
using System.Web.UI.Design;
namespace StyleLibFunctions
{
#region TestTableControl
[ToolboxData("<{0}:TestTableControl
runat=server></{0}:TestTableControl>"),Designer(typeof(TestTableC ompositeDes
igner))
]
public class TestTableControl: WebControl, INamingContainer
{
#region Variable Declaration
private Table _table;
private TableRow _tr;
private TableCell _td;
#endregion Variable Declaration
#region Overridden Properties
public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.Controls;
}
}
#endregion Overridden Properties
#region Overridden Methods
protected override void CreateChildControls ()
{
//clear controls
Controls.Clear();
//Create a Table object
_table = new Table();
_tr = new TableRow();
_td = new TableCell();
_td.Controls.Add(new LiteralControl("Cell Content"));
_tr.Cells.Add(_td);
_table.Rows.Add(_tr);
//add table to control tree
Controls.Add (_table);
}
protected override void Render(HtmlTextWriter writer)
{
_table.RenderControl(writer);
}
#endregion Overridden Methods
}
#endregion
public class TestTableCompositeDesigner : ControlDesigner
{
public override void Initialize(IComponent component)
{
if(!(component is INamingContainer) && !(component is TestTableControl))
{
throw new ArgumentException("Component must be a TestTableControl and
implement INamingContainer interface","component");
}
base.Initialize (component);
}
public override string GetDesignTimeHtml()
{
ControlCollection controls=((Control)Component).Controls;
return base.GetDesignTimeHtml ();
}
}
}
--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
[url]http://www.mansoft.fi[/url]
ASP.NET Forums Moderator, [url]www.asp.net[/url]
AspAlliance Columnist, [url]www.aspalliance.com[/url]
Email:
[email]joteke@aspalliance.com[/email]
<jb_in_marietta@yahoo.com> kirjoitti viestissä
news:1b62740d.0307011324.3686e47c@posting.google.c om...----> All,
>
> I have written a very simple custom composite control that includes a
> control of type System.Web.UI.WebControls.Table.
>
> The control renders fine in run time, but for some reason, it does not
> render properly in design time.
>
> In design time it renders something like this:
>
> [TestTableControl "TestTableControl1"]
>
>
> Could someone please explain why this control does not render in
> design time.
> (complete code is included below)
>
> Thanks in advance!!!
>
> --Jonathan
>
> -------------------------------------------------------------------------->
>
> using System;
> using System.Web;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.ComponentModel;
> using System.Collections;
>
>
> namespace StyleLibFunctions
> {
> #region TestTableControl
>
> [ToolboxData("<{0}:TestTableControl
> runat=server></{0}:TestTableControl>")]
> public class TestTableControl: WebControl
> {
> #region Variable Declaration
>
> private Table _table;
> private TableRow _tr;
> private TableCell _td;
>
> #endregion Variable Declaration
>
> #region Overridden Properties
> public override ControlCollection Controls
> {
> get
> {
> EnsureChildControls();
> return base.Controls;
> }
> }
> #endregion Overridden Properties
>
> #region Overridden Methods
> protected override void CreateChildControls ()
> {
> //clear controls
> Controls.Clear();
>
> //Create a Table object
> _table = new Table();
> _tr = new TableRow();
> _td = new TableCell();
> _td.Controls.Add(new LiteralControl("Cell Content"));
>
> _tr.Cells.Add(_td);
> _table.Rows.Add(_tr);
>
> //add table to control tree
> Controls.Add (_table);
>
> }
> protected override void Render(HtmlTextWriter writer)
> {
> _table.RenderControl(writer);
> }
> #endregion Overridden Methods
> }
> #endregion
> }
Teemu Keiski Guest



Reply With Quote

