0

I have an ASP.NET website that is not passing the W3C XHTML validation.

It doesn't pass validation because I place <div> content into a <asp:Label>, and so the resulting markup looks like:

<span><div>stackoverflow</div></span> <!-- INVALID; DIV INSIDE SPAN -->

However, after replacing all my <asp:Label> with <asp:Literal>, I get errors that <asp:Literal> cannot be nested inside another <asp:Literal>.

I don't really understand how I'm suppose to be solving this, since <asp:Literal> sounds like it would have otherwise been exactly what I wanted.

Is the correct solution to use <asp:PlaceHolder>?

Mr. Smith
  • 4,288
  • 7
  • 40
  • 82

2 Answers2

1

Try this solution

<div id="div" runat="server">
</div>

in code behind

div.InnerHtml = "<div>Example HTML</div>";
phnkha
  • 7,782
  • 2
  • 24
  • 31
-1

Duplicate, answered in: Using Panel or PlaceHolder

Short answer, an <asp:Panel> becomes a <div>, so you want something like

<asp:Panel>
  <asp:Label .../>
</asp:Panel>
Community
  • 1
  • 1
debracey
  • 6,517
  • 1
  • 30
  • 56
  • I don't exactly want a `
    ` either; I want nothing. `TEXT HERE` is stored as an `` which has me scared it may not always work.
    – Mr. Smith Jan 04 '13 at 03:04
  • How is it that you don't want a `div`, yet you accept an answer that does exactly the same thing as I showed...? – debracey Jan 04 '13 at 03:14
  • Firstly, it wouldn't be `
    ` it would be `
    `. Secondly, I like the lack of `` usage. Thirdly, it's not `` it would have been ``.
    – Mr. Smith Jan 04 '13 at 03:32
  • The point was to use the panel instead of a div, and then place your label inside there. namkha87's answer does produce `
    `. Finally, if you're using asp.net the whole point is to use asp controls....
    – debracey Jan 04 '13 at 06:09
  • namkha87's code, taken at face value, does indeed produce `
    `. I don't think he meant for his `InnerHtml` property to be wrapped with `
    ` though; his solution outputs `
    ` with trivial changes to his example code.
    – Mr. Smith Jan 04 '13 at 07:43