A question about Page Header

When you add a Literal control to Page Header, for example:

<head runat="server">
    <asp:Literal runat="server" ID ="literal" >Literal Test!</asp:Literal>
     <title>Untitled Page</title>
</head>

When you browser the page, you will find "Literal Test!" was displayed.

View the source code:
<head>
    Literal Test!
     <title>
          Untitled Page
     </title>
</head>

but if you use Developer Toolbar or Doc Inspector of FF, the source code is different:
<head>
    <title>
         Untitled Page
    </title>
</head>
<body>
   Literal Test!

  ......

</body>

I don't understand, anyone can tell me which is right and why they are different? thanks!

3 Comments

  • I think this is because it's invalid to just have untagged floating text in the header- the source code you see through the developer tool bar has already been run through the browser parser which trys to tidy up the source code before rendering it. So when you view source and see;

    Literal Test!

    Untitled Page


    ...that is actually what ASP.net is spitting out- however;



    Untitled Page



    Literal Test!

    ...is what your browser shuffles it around to, so that it can render it.

  • Do you mean that what we see through View Source of the browser itself is the original source code after Asp.net spitting out?
    If so, the View Source function of browser seems strange!

  • Yep, that's correct. Shawson is also correct that raw text should not be placed in the head - this (probably) violates the rules of the HTML or XHTML DTD defined in your doc type declaration.

    When the browser parses illegal HTML or XHTML markup like that, it will try to make corrections when transalting the source into the DOM. In this case the source is the markup that ASP.NET literally generates and that is what you see when you click "View Source".

    The DOM is the in-memory representation of your parsed source in the browser. When you use a DOM inspector, like the IE developer toolbar, FF Doc Inspector, or Firebug, what you are viewing is a reverse translation of the DOM back into HTML or XHTML. This will likely not be the same as the original markup generated by ASP.NET.

Comments have been disabled for this content.