Page.Header Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan header dokumen untuk halaman jika head
elemen ditentukan dengan runat=server
dalam deklarasi halaman.
public:
property System::Web::UI::HtmlControls::HtmlHead ^ Header { System::Web::UI::HtmlControls::HtmlHead ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.HtmlControls.HtmlHead Header { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Header : System.Web.UI.HtmlControls.HtmlHead
Public ReadOnly Property Header As HtmlHead
Nilai Properti
Yang HtmlHead berisi header halaman.
- Atribut
Contoh
Contoh kode berikut menunjukkan cara mengakses HtmlHead kontrol secara terprogram menggunakan Header properti .
title
Elemen dan style
elemen ditambahkan ke head
elemen halaman.
<%@ 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;
// <Snippet2>
// Add the style rule named bodyStyle to the header
// of the current page. The rule is for the body HTML element.
Page.Header.StyleSheet.CreateStyleRule(bodyStyle, null, "body");
// </Snippet2>
// 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 id="form1" 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>
<%@ 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">
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Create a Style object for the body of the page.
Dim bodyStyle As New Style()
bodyStyle.ForeColor = System.Drawing.Color.Blue
bodyStyle.BackColor = System.Drawing.Color.LightGray
' <Snippet2>
' Add the style rule named bodyStyle to the header
' of the current page. The rule is for the body HTML element.
Page.Header.StyleSheet.CreateStyleRule(bodyStyle, Nothing, "body")
' </Snippet2>
' Add the page title to the header element.
Page.Header.Title = "HtmlHead Example"
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1"
runat="server">
<title>To be replaced.</title>
</head>
<body>
<form id="Form1" 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>
Keterangan
Properti Header mendapatkan referensi ke HtmlHead objek yang bisa Anda gunakan untuk mengatur informasi header dokumen untuk halaman tersebut.
HtmlHead memungkinkan Anda menambahkan informasi seperti lembar gaya, aturan gaya, judul, dan metadata ke head
elemen.
Catatan
Menambahkan gaya secara terprogram menggunakan metode IStyleSheet antarmuka selama postback asinkron tidak didukung. Saat Anda menambahkan kapabilitas AJAX ke halaman Web, postback asinkron memperbarui wilayah halaman tanpa memperbarui seluruh halaman. Untuk informasi selengkapnya, lihat Gambaran Umum Microsoft Ajax.