Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Finding the head tag of a page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeremy - 26 Mar 2008 20:05 GMT
I've written a method that recursively loops through the control collections
on a page looking for a literal control called html.
Sometimes the html literal control will contain a child literal control
called head.  Sometimes the html literal control will not have a child
literal control called head, and instead will have the head html included in
its text property.  Why would asp.net sometimes parse the pages html into
literal controls and sometimes not?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- Use doctype to force browser into standard mode. Standard mode handles
css inheritance correctly. -->
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>test</title></head>
<body>
<form id="Form1" runat="server"></form>
</body>
</html>
bruce barker - 26 Mar 2008 21:05 GMT
in general, all the html between server controls is loaded into one html
literal. any html tag with a runat=server becomes its own html literal.

now some control parse their inner html and produce seperate control. for
example, the <table runat=server> control will convert all <tr> and <td> into
controls, and ignores everything else. the <head runat=server> will
automatically discover the title.

in your case some pages have the runat=server on the head and some don't.

note: the standard vs2005 page template create a <head runat=server>

-- bruce (sqlwork.com)

> I've written a method that recursively loops through the control collections
> on a page looking for a literal control called html.
[quoted text clipped - 16 lines]
> </body>
> </html>
David R. Longnecker - 26 Mar 2008 21:41 GMT
The Page object for each .NET web form automatically has a Header (which
is an HtmlHeader object) associated to it if your <head /> tag has runat="server"
in it.  From there, you can find things such as the Title and StyleSheets.  

If you wanted to inject controls, such as a literal control, into the Header,
you can by adding the control to the Header's ControlCollection.

LiteralControl testControl = new LiteralControl("<junk>Test</junk>");
Page.Header.Controls.Add(testControl);

generates:

<head>
<title>Untitled Page</title>
<junk>Test</junk>
</head>

If this isn't what you're looking for, could you provide a bit of background
on what you're trying to do?

HTH.

-dl

--
David R. Longnecker
http://blog.tiredstudent.com

> I've written a method that recursively loops through the control
> collections
[quoted text clipped - 21 lines]
> </body>
> </html>

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.