Professional Web Applications Themes

Using Table control in a custom composite control. Control does not render properly in design time. - ASP.NET Building Controls

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 ...

  1. #1

    Default 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

  2. #2

    Default 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

  3. #3

    Default 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]jotekeaspalliance.com[/email]

    <jb_in_marietta> kirjoitti viestissä
    news:1b62740d.0307011324.3686e47cposting.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

Similar Threads

  1. Custom control renders table but doesn't resize at design time.
    By Chubby Arse in forum ASP.NET Building Controls
    Replies: 0
    Last Post: October 6th, 10:18 AM
  2. custom control (with collection) do not render at Design time
    By rleblond@jeancoutu.com in forum ASP.NET Building Controls
    Replies: 1
    Last Post: September 27th, 01:15 PM
  3. Replies: 2
    Last Post: July 22nd, 10:58 PM
  4. q: 'composite' control: works fine, but no children design time ?
    By Juri Zenkevitch in forum ASP.NET Building Controls
    Replies: 0
    Last Post: April 7th, 10:07 AM
  5. Composite Control design time behavior
    By J.Marsch in forum ASP.NET Building Controls
    Replies: 2
    Last Post: October 1st, 07:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139