asp:label renders as inline


(I hope not posting this to the wrong forum. Maby it is a .net related question rather than an EPiServer question.)

Since I'm not really a .net developer but more of a designer with focus om W3C standards, I'm not sure whats giong on here. I've got my text output through a label control such as:

<asp:Label runat="server" ID="TextContent1"></asp:Label>

This will render:

<span id="ctl00_MySiteContent_TextContent1"></span>

'span' is an inline tag that does not allow block elements such as 'h1', 'h2', 'p' and so on inside it to validate with W3C (those block elements comes from the text editor, the content).

Is the only solution to do a <div runat="server"> to make the content holder a block element or is it possible to make the asp:label to render a 'div' instead of a 'span' (doing span{display:block; is not an option})?
Aug 07, 2008 15:13
Well, you could make an adapter and override some renderfunction for asp:label, or you can use <div><asp:literal .. /></div> instead.
Aug 07, 2008 23:52
Or use an <asp:Panel.... />
Aug 08, 2008 11:59

I belive it would be helpful if you could try to explain "why" you would like to use extra tags at all.


Is it to be able to switch content "on and off" ? I.e. use Visible = <%# something() %> or similar?


Or is it just to output plain text to the webbpage?

Aug 08, 2008 13:16

The ASP.NET Label control will render as a <label> element if you set the AssociatedControlID property.

If you want to render plain text, use the Literal control instead.

If you want to display/hide specific parts of a page, use the PlaceHolder control since it won't render any HTML whatsoever, except for the markup within the PlaceHolder tags.

Aug 09, 2008 22:16

Thanx guys, your answers were helpful!

I do not  understand your  question. As I stated in my first post  asp:label renders as an inline container e.g. <span><p>Content</p></span>. Since you cannon validate block elements (<p>, <ul> etc.) inside a span, I wanted to have a <div> instead so it renders <div><p>Content</p></div>. 


Aug 18, 2008 15:09