Freigeben über


HtmlGenericControl-Konstruktor (String)

Initialisiert eine neue Instanz der HtmlGenericControl-Klasse mit dem angegebenen Tag.

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)

Syntax

'Declaration
Public Sub New ( _
    tag As String _
)
'Usage
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
)

Parameter

  • tag
    Der Name des Elements, für das diese Instanz der Klasse erstellt wird.

Hinweise

Mit diesem Konstruktor können Sie eine neue Instanz der HtmlGenericControl-Klasse mit dem angegebenen Tag erstellen und initialisieren. Wird zum dynamischen Erstellen von Elementen von HTML-Serversteuerelementen verwendet, die nicht direkt von einer .NET Framework-Klasse dargestellt werden.

In der folgenden Tabelle werden die anfänglichen Eigenschaftenwerte für eine Instanz von HtmlGenericControl aufgeführt.

Eigenschaft

Anfangswert

TagName

Der Wert des tag-Parameters.

Hinweis

Wenn der tag-Parameter NULL (Nothing in Visual Basic) ist, wird die TagName-Eigenschaft auf String.Empty festgelegt.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie mithilfe des überladenen Konstruktors eine neue Instanz der HtmlGenericControl-Klasse erstellt wird.

<%@ 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 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 runat="server">
   <div>

      <h3> HtmlGenericControl Constructor Example </h3>

      <asp:PlaceHolder ID="ControlContainer"
                       runat="server"/>
   </div>
   </form>

</body>
</html>

Plattformen

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

HtmlGenericControl-Klasse
HtmlGenericControl-Member
System.Web.UI.HtmlControls-Namespace

Weitere Ressourcen

HTML-Serversteuerelemente