views:

92

answers:

2

I'm writing an ASP.NET custom composite control (Inherits System.Web.UI.WebControls.CompositeControl).

By default my control mark up renders surrounded by tags. I know I can over ride the property TagKey to set the return as whatever tag I want from the System.Web.UI.HtmlTextWriterTag enum.

My question: Can I make my control render without .NET adding markup around it?

A: 

Its possible to get rid of the containing tag with a CompositeControl, but its working against the way CompositeControl likes to work (see below)

The proper way, apparently, to set TagKey to whatever the main tag of your control actually is (a div, table, or whatever).

Then override AddAttributesToRender() to set the attributes you want on your wrapper tag.

The stuff you want inside the wrapping tags should be rendered by overriding the RenderContents() method.

CompositeControl inherits from WebControl, see a discussion of the user of TagKey and AddAttributesToRender() here.

Someone on GeeksWithBlogs writes about a similar issue here

To just get rid of the wrapping though, see this forum post that shows a way to override the control constructor and the RenderBeginTag and RenderEndTag methods to remove the wrapping tags.

codeulike
MADCookie
A: 

Couldn't you just override the Render() method, forcing it to render only the contents? Maybe something like this would do the trick:

public override void Render(HtmlTextWriter writer)
{
    RenderContents(writer);
}
Jørn Schou-Rode