HtmlHead Class
Assembly: System.Web (in system.web.dll)
The HtmlHead control provides programmatic access to the HTML <head> element on the server. The HTML <head> element is a container for additional information about the page. For more information on HTML server controls, see HTML Server Controls.
The HtmlHead control is useful for specifying page formatting information that can be accessed at run time.
| Topic | Location |
|---|---|
| How to: Add HTML Server Controls to a Web Page Using ASP.NET Syntax | Building ASP .NET Web Applications |
| How to: Set HTML Server Control Properties Programmatically | Building ASP .NET Web Applications |
| How to: Add HTML Server Controls to a Web Page Using ASP.NET Syntax | Building ASP .NET Web Applications |
| How to: Set HTML Server Control Properties Programmatically | Building ASP .NET Web Applications |
The following code example demonstrates how to programmatically access the HtmlHead control to dynamically add a <title> element and a <style> element to the <head> element of the page.
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, System.EventArgs e) { // Create a Style object for the body of the page. Style bodyStyle = new Style(); bodyStyle.ForeColor = System.Drawing.Color.Blue; bodyStyle.BackColor = System.Drawing.Color.LightGray; // Add the style to the header of the current page. Page.Header.StyleSheet.CreateStyleRule(bodyStyle, null, "BODY"); // Add the page title to the header element. Page.Header.Title = "HtmlHead Example"; } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="head1" runat="server"> <title>To be replaced.</title> </head> <body> <form runat="server"> <h3>HtmlHead Class Example</h3> <asp:label id="Label1" text = "View the HTML source code of this page to see the title and body style added to the header element." runat="server"> </asp:label> </form> </body> </html>
- AspNetHostingPermission to run the HtmlHead control in a hosted environment. Associated enumeration: Minimal
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.