Removing SPAN-tags around server control

I had to write some ASP.NET server controls for our current SharePoint portal project. We have very nice DIV-based layout and using standard components that generate table and a lot of JavaScript seems to me like an bad idea. I found out that server controls put container tags around their mark-up. I needed my own tags around output and I found a way how to achieve it.

There are two rendering methods I needed to override: RenderBeginTag and RenderEndTag. Be default these methods create <span> and </span> tag before and after web part outout respectively. When creating web parts DIV-tags are created instead SPANs. Now let’s remove these tags. You need only these two simple overrides:


public override void RenderBeginTag(HtmlTextWriter writer)
{
}

public override void RenderEndTag(HtmlTextWriter writer)
{
}

That’s it.


Leave a Reply

Your email address will not be published. Required fields are marked *