public ref class HtmlMeta : System::Web::UI::HtmlControls::HtmlControl
public class HtmlMeta : System.Web.UI.HtmlControls.HtmlControl
type HtmlMeta = class
inherit HtmlControl
Public Class HtmlMeta
Inherits HtmlControl
HtmlMeta
下面的代码示例演示如何使用
HtmlMeta
控件定义网页的 HTML
<meta>
元素。 定义了两
<meta>
个元素,一个列表关键字描述页面,一个列出页面创建日期。
<%@ 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, EventArgs e)
// Create two instances of an HtmlMeta control.
HtmlMeta hm1 = new HtmlMeta();
HtmlMeta hm2 = new HtmlMeta();
// Get a reference to the page header element.
HtmlHead head = (HtmlHead)Page.Header;
// Define an HTML <meta> element that is useful for search engines.
hm1.Name = "keywords";
hm1.Content = "words that describe your web page";
head.Controls.Add(hm1);
// Define an HTML <meta> element with a Scheme attribute.
hm2.Name = "date";
hm2.Content = DateTime.Now.ToString("yyyy-MM-dd");
hm2.Scheme = "YYYY-MM-DD";
head.Controls.Add(hm2);
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HtmlMeta Example</title>
</head>
<form id="form1" runat="server">
View the HTML source code of the page to see the two HTML meta elements added.
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Create two instances of an HtmlMeta control.
Dim hm1 As New HtmlMeta()
Dim hm2 As New HtmlMeta()
' Get a reference to the page header element.
Dim head As HtmlHead = Page.Header
' Define an HTML <meta> element that is useful for search engines.
hm1.Name = "keywords"
hm1.Content = "words that describe your web page"
head.Controls.Add(hm1)
' Define an HTML <meta> element with a Scheme attribute.
hm2.Name = "date"
hm2.Content = DateTime.Now.ToString("yyyy-MM-dd")
hm2.Scheme = "YYYY-MM-DD"
head.Controls.Add(hm2)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HtmlMeta Example</title>
</head>
<form id="form1" runat="server">
View the HTML source code of the page to see the two HTML meta elements added.
</form>
</body>
</html>
该
HtmlMeta
控件提供对服务器上的 HTML
<meta>
元素的编程访问。 HTML
<meta>
元素是有关呈现页面的数据的容器,但不是页面内容本身。 标记
<meta>
放置在开始和结束 HTML
<head>
元素之间。 每个
<meta>
元素描述元数据属性名称及其关联值。
HtmlMeta
使用控件的属性
Name
指定元数据属性名称,以及
Content
用于指定元数据属性值的属性。 使用该
Scheme
属性可向用户代理指定有关如何解释元数据属性的其他信息。
HttpEquiv
使用 HTTP 检索生成的元数据属性时,使用属性代替
Name
属性。
可以使用对象的属性获取对页面
<head>
元素
Header
的
Page
引用。