HtmlGenericControl類可以創建服務器端控件,以映射到相應的Html元素,而不被.Net框架類所轉換。比如<body><span>等。下面的例子就是利用HtmlGenericControl類動態創建Title元素的。
ChangePageTitle.ASPx
<%@ Page Language="<a href="http://dev.21tx.com/language/vb/" target="_blank">VB</a>" AutoEventWireup="false" Codebehind="ChangePageTitle.ASPx.vb"
Inherits="ASPx<a href="http://dev.21tx.com/web/" target="_blank">Web</a>.mengxianhui.com.ChangePageTitle"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD Html 4.0 Transitional//EN">
<Html>
<HEAD>
<TITLE ID="MyPageTitle" RUNAT="server"></TITLE>
<META NAME="CODE_LANGUAGE" CONTENT="Visual Basic 7.0">
<META NAME="vs_defaultClIEntScript" CONTENT="<a href="http://dev.21tx.com/web/Javascript/" target="_blank">JavaScript</a>">
<META NAME="vs_targetSchema" CONTENT="http://schemas.microsoft.com/intellisense/IE5">
</HEAD>
<BODY MS_POSITIONING="GridLayout">
<FORM ID="Form1" METHOD="post" RUNAT="server">
</FORM>
</BODY>
</Html>
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