HtmlGenericControl 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 HtmlGenericControl 类的新实例。
重载
HtmlGenericControl() |
使用默认值初始化 HtmlGenericControl 类的新实例。 |
HtmlGenericControl(String) |
使用指定的标记初始化 HtmlGenericControl 类的新实例。 |
HtmlGenericControl()
使用默认值初始化 HtmlGenericControl 类的新实例。
public:
HtmlGenericControl();
public HtmlGenericControl ();
Public Sub New ()
示例
下面的代码示例演示如何使用无参数构造函数创建 类的新实例 HtmlGenericControl 。
<%@ 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)
{
// Create a new HtmlGenericControl.
HtmlGenericControl NewControl = new HtmlGenericControl();
// Set the properties of the new HtmlGenericControl control.
NewControl.ID = "NewControl";
NewControl.InnerHtml = "This is a dynamically created HTML server control.";
// Add the new HtmlGenericControl to the Controls collection of the
// PlaceHolder control.
ControlContainer.Controls.Add(NewControl);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>HtmlGenericControl Constructor Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3> HtmlGenericControl Constructor Example </h3>
<asp:PlaceHolder ID="ControlContainer"
runat="server"/>
</div>
</form>
</body>
</html>
<%@ 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">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Create a new HtmlGenericControl.
Dim NewControl As New HtmlGenericControl()
' Set the properties of the new HtmlGenericControl control.
NewControl.ID = "NewControl"
NewControl.InnerHtml = "This is a dynamically created HTML server control."
' Add the new HtmlGenericControl to the Controls collection of the
' PlaceHolder control.
ControlContainer.Controls.Add(NewControl)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HtmlGenericControl Constructor Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3> HtmlGenericControl Constructor Example </h3>
<asp:PlaceHolder ID="ControlContainer"
runat="server"/>
</div>
</form>
</body>
</html>
注解
使用此构造函数使用默认值创建和初始化 类的新实例 HtmlGenericControl 。 它通常用于动态创建服务器端 <span>
元素。
下表显示了 实例 HtmlGenericControl的初始属性值。
属性 | 初始值 |
---|---|
TagName |
“span”文本字符串。 |
适用于
HtmlGenericControl(String)
使用指定的标记初始化 HtmlGenericControl 类的新实例。
public:
HtmlGenericControl(System::String ^ tag);
public HtmlGenericControl (string tag);
new System.Web.UI.HtmlControls.HtmlGenericControl : string -> System.Web.UI.HtmlControls.HtmlGenericControl
Public Sub New (tag As String)
参数
- tag
- String
要为其创建该类的此实例的元素的名称。
示例
下面的代码示例演示如何使用重载构造 HtmlGenericControl 函数创建 类的新实例。
<%@ 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)
{
// Create a new HtmlGenericControl.
HtmlGenericControl NewControl = new HtmlGenericControl("div");
// Set the properties of the new HtmlGenericControl control.
NewControl.ID = "NewControl";
NewControl.InnerHtml = "This is a dynamically created HTML server control.";
// Add the new HtmlGenericControl to the Controls collection of the
// PlaceHolder control.
ControlContainer.Controls.Add(NewControl);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HtmlGenericControl Constructor Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3> HtmlGenericControl Constructor Example </h3>
<asp:PlaceHolder ID="ControlContainer"
runat="server"/>
</div>
</form>
</body>
</html>
<%@ 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">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Create a new HtmlGenericControl.
Dim NewControl As New HtmlGenericControl("div")
' Set the properties of the new HtmlGenericControl control.
NewControl.ID = "NewControl"
NewControl.InnerHtml = "This is a dynamically created HTML server control."
' Add the new HtmlGenericControl to the Controls collection of the
' PlaceHolder control.
ControlContainer.Controls.Add(NewControl)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HtmlGenericControl Constructor Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3> HtmlGenericControl Constructor Example </h3>
<asp:PlaceHolder ID="ControlContainer"
runat="server"/>
</div>
</form>
</body>
</html>
注解
使用此构造函数使用指定的标记创建和初始化 类的新实例 HtmlGenericControl 。 这使你可以动态创建任何不直接由 .NET Framework 类表示的 HTML 服务器控件元素。
下表显示了 实例 HtmlGenericControl的初始属性值。
属性 | 初始值 |
---|---|
TagName |
tag 参数的值。 |
注意
tag
如果 参数为 null
,则 TagName 属性设置为 String.Empty。