Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I include thead in a runat="server" table element?

I'm upgrading a big web site project from Visual Studio 2010 to 2012. Throughout my project, I have table elements with the runat="server" attribute. Many of these have thead elements inside of them. When I open it in 2012 and and try to build, I get the following error:

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

Removing the runat="server" attribute or commenting out thead fixes it. Commenting out only the tr element inside of thead does not fix it. Here is a simplified example that reproduces the problem:

<%@ 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>

The error occurs where the table element opens.

How can I fix this without doing one of the following?

  • Removing the runat="server" attribute
  • Removing the thead element
  • Changing it to an asp:table element

Bonus up vote for someone who explains what 2012 is doing differently that is causing this.

UPDATE:

The problem does not occur in a web app, only in a web site.

The project isn't actually be upgraded, just my development environment. In both cases, I'm using the 4.0 framework

I tried using the 4.5 framework, but it didn't help.

Sept 10th, 2012: I have an open case with Microsoft support. Their dev team is looking into it.

Oct. 24, 2012: Since .NET 4.5 replaces 4.0, I can no longer compile in VS 2010 also. The problem I am experiencing is purely .NET - not Visual Studio.

like image 989
Keith Walton Avatar asked Aug 27 '12 20:08

Keith Walton


People also ask

How do I use a Runat server?

To make these elements programmable, add a runat="server" attribute to the HTML element. This attribute indicates that the element should be treated as a server control. The id attribute is added to identify the server control. The id reference can be used to manipulate the server control at run time.

What is the use of Runat attribute?

The runat attribute basically tells ASP.Net that it needs to parse the element, its attributes and it's contents as a server control. Enabling code, on the server, to be executed to configure the response. Without it, any child controls contained within the <head> section will not get parsed.


2 Answers

Fix for this issue is available now. http://support.microsoft.com/kb/2750149 for windows 8 and http://support.microsoft.com/kb/2750147 for Windows 7 platform.

like image 194
Anand Avatar answered Oct 24 '22 14:10

Anand


For partial solution you can move that <th> front-end code to the back-end code. That should take care of the compilation problem. Don't know what to do about <tbody> tags though. If you view HTML of your page as it stands now, I doubt that they render anyway. Here is why.

like image 43
user1720412 Avatar answered Oct 24 '22 13:10

user1720412