Asp.net

如何在 runat=‘server’ 表格元素中包含 thead?

  • August 27, 2012

我正在將一個大型網站項目從 Visual Studio 2010 升級到 2012。在我的整個項目中,我都有具有該屬性table的元素。runat="server"其中許多都包含其中的thead元素。當我在 2012 年打開它並嘗試建構時,我收到以下錯誤:

Value of type 'System.Web.UI.HtmlControls.HtmlGenericControl' cannot be converted to 'System.Web.UI.HtmlControls.HtmlTableRow'

刪除runat="server"屬性或註釋掉thead它會修復它。僅註釋掉其中的tr元素thead並不能修復它。這是一個重現問題的簡化範例:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title></title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
       <table id="Example" runat="server">
           <thead>
               <tr>
                   <th>test</th>
               </tr>
           </thead>
       </table>
   </div>
   </form>
</body>
</html>

錯誤發生在table元素打開的地方。

如何在不執行以下操作之一的情況下解決此問題?

  • 刪除runat="server"屬性
  • 移除thead元素
  • 將其更改為asp:table元素

對解釋 2012 年的不同做法導致此問題的人進行額外投票。

更新:

該問題不會出現在 Web應用程序中,只會出現在網站中。

該項目實際上並沒有升級,只是我的開發環境。在這兩種情況下,我都使用 4.0 框架

我嘗試使用 4.5 框架,但沒有幫助。

2012 年 9 月 10 日:我有一個 Microsoft 支持的未決案例。他們的開發團隊正在研究它。

2012 年 10 月 24 日:由於 .NET 4.5 取代了 4.0,我也無法再在 VS 2010 中編譯。我遇到的問題純粹是 .NET - 而不是 Visual Studio。

現已提供此問題的修復程序。 <http://support.microsoft.com/kb/2750149>用於 Windows 8 和<http://support.microsoft.com/kb/2750147>用於 Windows 7 平台。

引用自:https://stackoverflow.com/questions/12148825