HtmlGenericControl的作用是:定义不由特定的 .NET Framework 类表示的所有 HTML 服务器控件元素的方法、属性和事件。
使用此类可以表示不直接用 .NET Framework 类表示的 HTML 服务器控件元素,如 <span>、<div>、<body> 。
下面的代码示例演示如何使用 HtmlGenericControl 类表示 <body> 元素。
Visual Basic 复制代码
<%@ 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">
Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Body.Attributes("bgcolor") = ColorSelect.Value
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HtmlGenericControl Example</title>
</head>
<body id="Body"
runat="server">
<h3>HtmlGenericControl Example</h3>
<form id="form1" runat="server">
<div>
<br />
Select a background color for the page: <br />
<select id="ColorSelect"
runat="server">
<option>White</option>
<option>LightBlue</option>
<option>LightGreen</option>
<option>Yellow</option>
</select>
<input type="submit"
runat="server"
value="Apply"
onserverclick="SubmitBtn_Click" id="Submit1" />
</div>
</form>
</body>
</html>
C# 复制代码
<%@ 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 SubmitBtn_Click(object sender, EventArgs e)
{
Body.Attributes["bgcolor"] = ColorSelect.Value;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HtmlGenericControl Example</title>
</head>
<body id="Body"
runat="server">
<h3>HtmlGenericControl Example</h3>
<form id="form1" runat="server">
<div>
<br />
Select a background color for the page: <br />
<select id="ColorSelect"
runat="server">
<option>White</option>
<option>LightBlue</option>
<option>LightGreen</option>
<option>Yellow</option>
</select>
<input type="submit"
runat="server"
value="Apply"
onserverclick="SubmitBtn_Click" id="Submit1" />
</div>
</form>
</body>
</html>
希望对你有所帮助! |