タグを指定して、HtmlGenericControl クラスの新しいインスタンスを初期化します。
名前空間: System.Web.UI.HtmlControls
アセンブリ: System.Web (system.web.dll 内)
構文
'宣言
Public Sub New ( _
tag As String _
)
'使用
Dim tag As String
Dim instance As New HtmlGenericControl(tag)
public HtmlGenericControl (
string tag
)
public:
HtmlGenericControl (
String^ tag
)
public HtmlGenericControl (
String tag
)
public function HtmlGenericControl (
tag : String
)
適用できません。
パラメータ
- tag
クラスのこのインスタンスを作成するための要素の名前。
解説
このコンストラクタを使用して、指定したタグで HtmlGenericControl クラスの新しいインスタンスを作成し、初期化します。これにより、.NET Framework クラスで直接表されない HTML サーバー コントロール要素を動的に作成できるようになります。
HtmlGenericControl のインスタンスの初期プロパティ値を次の表に示します。
プロパティ |
初期値 |
---|---|
TagName |
tag パラメータの値。 |
![]() |
---|
tag パラメータが null 参照 (Visual Basic では Nothing) に設定されると、TagName プロパティは String.Empty に設定されます。 |
使用例
オーバーロードされたコンストラクタを使用して、HtmlGenericControl クラスの新しいインスタンスを作成する方法を次のコード例に示します。
<%@ 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>
<%@ 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>
プラットフォーム
Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition
Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。
バージョン情報
.NET Framework
サポート対象 : 3.0,2.0,1.1,1.0
参照
関連項目
HtmlGenericControl クラス
HtmlGenericControl メンバ
System.Web.UI.HtmlControls 名前空間