rendering child controls in designer

Discussion in 'ASP .Net Building Controls' started by johnny, Aug 29, 2003.

  1. johnny

    johnny Guest

    I have been unable to get some of my custom server controls that have
    children to render properly in the vs.net designer. I have gone
    through other postings and tried their suggestions, but nothing has
    worked. Below are a couple of simple controls I came up with to
    illustrate my problem. Hopefully, someone can help me out.



    [ParseChildren(false), PersistChildren(true)]

    public class ChildControl : Control, INamingContainer

    {

    public override ControlCollection Controls

    {

    get

    {

    EnsureChildControls();

    return base.Controls;

    }

    }



    protected override void Render(HtmlTextWriter writer)

    {

    writer.Write("<tr><td>Hello");

    base.Render (writer);

    writer.Write("</td></tr>");

    }

    }



    [ParseChildren(false), PersistChildren(true)]

    public class ParentControl : Control, INamingContainer

    {

    public override ControlCollection Controls

    {

    get

    {

    EnsureChildControls();

    return base.Controls;

    }

    }



    protected override void Render(HtmlTextWriter writer)

    {

    writer.Write("<table>");

    base.Render (writer);

    writer.Write("</table>");

    }


    Then in the aspx file:



    <form id="Form1" method="post" runat="server">

    <Custom:parentControl id="p" runat="server">

    <Custom:ChildControl id="c1" runat="server" />

    <Custom:ChildControl id="c2" runat="server" />

    </Custom:parentControl>

    </form>



    Thanks
     
    johnny, Aug 29, 2003
    #1
    1. Advertisements

  2. johnny

    johnny Guest

    Thank you for your response.

    I did as you recommended, but it still didn't work. I added a
    constructor to MyDesigner and set ReadOnly=false in it. That seemed
    to let the children render. However, it still didn't render properly.
    The HTML should produce a table with two rows, but the designer showed
    the two children side by side.

    Any more suggestions would be appreciated
     
    johnny, Aug 30, 2003
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.