HtmlGenericControl Konstruktorok

Definíció

Inicializálja a HtmlGenericControl osztály új példányát.

Túlterhelések

Name Description
HtmlGenericControl()

Inicializálja az osztály új példányát alapértelmezett HtmlGenericControl értékekkel.

HtmlGenericControl(String)

Inicializálja az osztály új példányát HtmlGenericControl a megadott címkével.

HtmlGenericControl()

Inicializálja az osztály új példányát alapértelmezett HtmlGenericControl értékekkel.

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

Példák

Az alábbi példakód bemutatja, hogyan hozható létre az osztály új példánya a HtmlGenericControl paraméter nélküli konstruktor használatával.

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

Megjegyzések

Ezzel a konstruktorsal létrehozhatja és inicializálhatja az HtmlGenericControl osztály új példányát az alapértelmezett értékekkel. Gyakran használják kiszolgálóoldali <span> elem dinamikus létrehozására.

Az alábbi táblázat a példány kezdeti tulajdonságértékét HtmlGenericControlmutatja be.

Ingatlan Kezdeti érték
TagName A "span" literális sztring.

A következőre érvényes:

HtmlGenericControl(String)

Inicializálja az osztály új példányát HtmlGenericControl a megadott címkével.

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)

Paraméterek

tag
String

Annak az elemnek a neve, amelyhez az osztálynak ez a példánya létrejön.

Példák

Az alábbi példakód bemutatja, hogyan hozható létre az osztály új példánya a HtmlGenericControl túlterhelt konstruktor használatával.

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

Megjegyzések

Ezzel a konstruktorsal létrehozhatja és inicializálhatja az HtmlGenericControl osztály új példányát a megadott címkével. Így dinamikusan hozhat létre olyan HTML-kiszolgálóvezérlő elemet, amelyet nem közvetlenül egy .NET Framework-osztály jelöl.

Az alábbi táblázat a példány kezdeti tulajdonságértékét HtmlGenericControlmutatja be.

Ingatlan Kezdeti érték
TagName A paraméter értéke tag .

Note

Ha a tag paraméter az null, akkor a TagName tulajdonság értéke String.Empty.

A következőre érvényes: