ASP.NET CompositeControl with child controls that contain children

Posted by tomfanning on Stack Overflow See other posts from Stack Overflow or by tomfanning
Published on 2010-06-10T15:09:34Z Indexed on 2010/06/10 15:13 UTC
Read the original article Hit count: 391

I am building an ASP.NET server control which extends CompositeControl.

I need fine grained control over the rendering, so I override Render() and output the child controls myself, interspersed with HTML generation code:

writer.AddStyleAttribute("float", "left");
writer.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
writer.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Strong);
writer.Write("Table");
writer.RenderEndTag(); // strong
writer.WriteBreak();
tableList.RenderControl(writer);
writer.RenderEndTag(); // div

This works really well for user controls that just contain simple controls without children of their own.

However, if I want to use something like a MultiView or an UpdatePanel I run into problems, since I can't override Render() on View or UpdatePanel without extending them, and if I do extend them the implementation would presumably have to depend on FindControl() voodoo to get references to the right controls during render.

That doesn't sound like the right way to do this - is there a better way?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-ajax