简体   繁体   English

如何通过vb.net aspx页面避免“跨度嵌套表” w3c验证错误?

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

I am trying to make my site fully w3c validator compliant. 我试图使我的网站完全符合w3c验证程序的要求。

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. 目前,我遇到了一个错误,因为以编程方式生成并插入标签的text属性中的表显示为嵌套在span标记中的表。

eg 例如

MyPage.aspx.vb MyPage.aspx.vb

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

MyPage.aspx 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: 然后,当我在validator.w3.org上验证我的页面时,出现以下错误:

document type does not allow element "table" here; 文档类型此处不允许元素“表”; missing one of "object", "applet", "map", "iframe", "button", "ins", "del" start-tag 缺少“对象”,“小程序”,“地图”,“ iframe”,“按钮”,“ ins”,“ del”开始标签之一

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

使用Literal而不是Label来避免包装<span>元素:

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

使用面板并向其中添加一个generichtml控件。

Why not just use a Table control: 为什么不只使用Table控件:

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

Then simply create the columns and rows and add them to the table server side. 然后,只需创建列和行,并将它们添加到表服务器端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM