Search code examples
c#htmlhtml-tablecolgroup

Colgroup tag in code but missing from view source or debugger tool


This is sort of the opposite of this question Why does firebug add <tbody> to <table>? and may end up being the same answer but I want to confirm.

I have a colgroup in my code that, when I use Firebug or IE debugging tools, it just vanishes. See the images below.

My code It's there damnit!!

Source in Firebug Where the #$&% did it go!!


Solution

  • The following question Table caption does not show when it is runat=server explains that

    A complex table model is not supported. You cannot have an HtmlTable control with nested caption, col, colgroup, tbody, thead, or tfoot elements. These elements are removed without warning and do not appear in the output HTML. MSDN

    When I create the following HTML

    <table border="1">
      <colgroup>    
        <col span="2" style="background-color:orange"></col>
      </colgroup>
      <tr>
        <td>column 1</td>
        <td>column 2</td>
        <td>column 3</td>
      </tr>
    </table>
    

    The colgroup/col tags are still there

    My best guess is that since your table tag is being with runat="server", the C# parser must be removing it. You can prove that by looking at the actual HTML source that is sent to the client, that is use "view source" instead of looking at the generated DOM.

    One of the reasons I can't stand this mix of server and client code writing my HTML for me....