Share via


HtmlGenericControl Konstruktoren

Definition

Initialisiert eine neue Instanz der HtmlGenericControl-Klasse.

Überlädt

HtmlGenericControl()

Initialisiert eine neue Instanz der HtmlGenericControl-Klasse mit Standardwerten.

HtmlGenericControl(String)

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

HtmlGenericControl()

Initialisiert eine neue Instanz der HtmlGenericControl-Klasse mit Standardwerten.

public:
 HtmlGenericControl();
public HtmlGenericControl ();
Public Sub New ()

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie sie mithilfe des parameterlosen Konstruktors eine neue instance der HtmlGenericControl -Klasse erstellen.

<%@ 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>

Hinweise

Verwenden Sie diesen Konstruktor, um eine neue instance der HtmlGenericControl -Klasse mithilfe der Standardwerte zu erstellen und zu initialisieren. Es wird häufig verwendet, um ein serverseitiges <span> Element dynamisch zu erstellen.

Die folgende Tabelle zeigt die anfänglichen Eigenschaftswerte für eine instance von HtmlGenericControl.

Eigenschaft Anfangswert
TagName Die "span"-Literalzeichenfolge.

Gilt für:

HtmlGenericControl(String)

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

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)

Parameter

tag
String

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

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie sie mithilfe des überladenen Konstruktors eine neue instance der HtmlGenericControl -Klasse erstellen.

<%@ 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>

Hinweise

Verwenden Sie diesen Konstruktor, um eine neue instance der -Klasse mit dem HtmlGenericControl angegebenen Tag zu erstellen und zu initialisieren. Dadurch können Sie jedes HTML-Serversteuerelementelement dynamisch erstellen, das nicht direkt von einer .NET Framework-Klasse dargestellt wird.

Die folgende Tabelle zeigt die anfänglichen Eigenschaftswerte für eine instance von HtmlGenericControl.

Eigenschaft Anfangswert
TagName Der Wert des tag-Parameters.

Hinweis

Wenn der tag Parameter ist null, wird die TagName -Eigenschaft auf String.Emptyfestgelegt.

Gilt für: