How do I avoid a “table nested in span” w3c validation error with a vb.net aspx page?

StackOverflow https://stackoverflow.com/questions/2383289

  •  24-09-2019
  •  | 
  •  

문제

I am trying to make my site fully w3c validator compliant.

At the moment, I am getting an error because a table which is generated programatically and insterted into a label's text attribute shows as a table nested in a span tag.

e.g

MyPage.aspx.vb

strHtml = "<table><tr><td>Hello World</td></tr></table>" 
Me.myTable.Text = strHtml

MyPage.aspx

<asp:Label ID="myTable" runat="server" Text="testimonialTable"></asp:Label> 

Renders as:

<span id="ctl00_Main_myTable">
<table><tr><td>Hello World</td></tr></table>
</span>

When I then validate my page at validator.w3.org I get the following error:

document type does not allow element "table" here; missing one of "object", "applet", "map", "iframe", "button", "ins", "del" start-tag

The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.

I assume this is because I'm trying to put a block element (table) inside an inline element (span) - but I don't know how else to do this!

Anyone got any idea of a workaround?

Thanks,

Ben

도움이 되었습니까?

해결책

Use a Literal instead of a Label to avoid the wrapping <span> element:

<asp:Literal ID="myTable runat="server" />

다른 팁

Use a panel and add a generichtml control to it.

Why not just use a Table control:

<asp:Table ID="myTable" runat="server" />

Then simply create the columns and rows and add them to the table server side.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top