HtmlTitle.Text 属性

定义

获取或设置 HTML <title> 元素的文本。

public:
 virtual property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerDefaultProperty)]
public virtual string Text { get; set; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerDefaultProperty)>]
member this.Text : string with get, set
Public Overridable Property Text As String

属性值

HTML <title> 元素的文本。 默认值为空字符串 ("")。

属性

示例

下面的代码示例演示如何使用 Text 控件的 HtmlTitle 属性动态更改网页的标题。


<%@ 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">
  
  void Page_Load(object sender, EventArgs e)
  {

    if (Page.Header != null)
    {
      
      Page.Header.Title = "Welcome!  The time is: " + System.DateTime.Now;
      
    }
    
  }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head id="Head1" runat="server">
    <title>HtmlTitle Example</title>
</head>

  <body>

    <form id="form1" runat="server">

      <h3>HtmlTitle Example</h3>

    </form>

  </body>

</html>

<%@ Page Language="VB" AutoEventWireup="true"%>

<!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)
  
    If (Page.Header IsNot Nothing) Then

      Page.Header.Title = "Welcome!  The time is: " & System.DateTime.Now

    End If

  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head id="Head1" runat="server">
    <title>HtmlTitle Example</title>
</head>

  <body>

    <form id="form1" runat="server">

      <h3>HtmlTitle Example</h3>

    </form>

  </body>

</html>

注解

Text使用 属性可以指定或确定网页的标题。

适用于