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 Instanz 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 Instanz der Klasse mithilfe der HtmlGenericControl Standardwerte zu erstellen und zu initialisieren. Es wird häufig verwendet, um ein serverseitiges <span> Element dynamisch zu erstellen.

In der folgenden Tabelle sind die anfänglichen Eigenschaftswerte für eine Instanz von HtmlGenericControl.

Eigenschaft Anfangswert
TagName Die Literalzeichenfolge "span".

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 Instanz 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 Instanz der Klasse mithilfe des HtmlGenericControl angegebenen Tags zu erstellen und zu initialisieren. Auf diese Weise können Sie jedes HTML-Serversteuerelementelement dynamisch erstellen, das nicht direkt durch eine .NET Framework Klasse dargestellt wird.

In der folgenden Tabelle sind die anfänglichen Eigenschaftswerte für eine Instanz von HtmlGenericControl.

Eigenschaft Anfangswert
TagName Der Wert des tag-Parameters.

Hinweis

Wenn der tag Parameter lautet null, wird die TagName Eigenschaft auf String.Empty.

Gilt für: