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