利用HtmlGenericControl类,动态改变Title文字
HtmlGenericControl类可以创建服务器端控件,以映射到相应的HTML元素,而不被.NET框架类所转换。比如<body><span>等。下面的例子就是利用HtmlGenericControl类动态创建Title元素的。
ChangePageTitle.aspx
&lt;%@ Page Language="vb" AutoEventWireup="false" Codebehind="ChangePageTitle.aspx.vb" Inherits="aspxWeb.mengxianhui.com.ChangePageTitle"%&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt; &lt;HTML&gt; &lt;HEAD&gt; &lt;TITLE ID="MyPageTitle" RUNAT="server"&gt;&lt;/TITLE&gt; &lt;META NAME="CODE_LANGUAGE" CONTENT="Visual Basic 7.0"&gt; &lt;META NAME="vs_defaultClientScript" CONTENT="JavaScript"&gt; &lt;META NAME="vs_targetSchema" CONTENT="http://schemas.microsoft.com/intellisense/ie5"&gt; &lt;/HEAD&gt; &lt;BODY MS_POSITIONING="GridLayout"&gt; &lt;FORM ID="Form1" METHOD="post" RUNAT="server"&gt; &lt;/FORM&gt; &lt;/BODY&gt; &lt;/HTML&gt;
ChangePageTitle.aspx.vb
Public Class ChangePageTitle Inherits System.Web.UI.Page Protected MyPageTitle As New HtmlGenericControl() Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load MyPageTitle.InnerText = "【孟宪会之精彩世界】之.NET开发者乐园" End Sub End Class