Udostępnij za pośrednictwem


HtmlGenericControl Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy HtmlGenericControl.

Przeciążenia

Nazwa Opis
HtmlGenericControl()

Inicjuje nowe wystąpienie klasy HtmlGenericControl z wartościami domyślnymi.

HtmlGenericControl(String)

Inicjuje nowe wystąpienie HtmlGenericControl klasy przy użyciu określonego tagu.

HtmlGenericControl()

Inicjuje nowe wystąpienie klasy HtmlGenericControl z wartościami domyślnymi.

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

Przykłady

W poniższym przykładzie kodu pokazano, jak utworzyć nowe wystąpienie HtmlGenericControl klasy przy użyciu konstruktora bez parametrów.

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

Uwagi

Użyj tego konstruktora, aby utworzyć i zainicjować nowe wystąpienie HtmlGenericControl klasy przy użyciu wartości domyślnych. Jest on często używany do dynamicznego tworzenia elementu po stronie <span> serwera.

W poniższej tabeli przedstawiono początkowe wartości właściwości dla wystąpienia HtmlGenericControlklasy .

Majątek Wartość początkowa
TagName Ciąg literału "span".

Dotyczy

HtmlGenericControl(String)

Inicjuje nowe wystąpienie HtmlGenericControl klasy przy użyciu określonego tagu.

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)

Parametry

tag
String

Nazwa elementu, dla którego jest tworzone to wystąpienie klasy.

Przykłady

W poniższym przykładzie kodu pokazano, jak utworzyć nowe wystąpienie HtmlGenericControl klasy przy użyciu przeciążonego konstruktora.

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

Uwagi

Użyj tego konstruktora, aby utworzyć i zainicjować nowe wystąpienie HtmlGenericControl klasy przy użyciu określonego tagu. Dzięki temu można dynamicznie tworzyć dowolny element kontroli serwera HTML, który nie jest bezpośrednio reprezentowany przez klasę programu .NET Framework.

W poniższej tabeli przedstawiono początkowe wartości właściwości dla wystąpienia HtmlGenericControlklasy .

Majątek Wartość początkowa
TagName Wartość parametru tag .

Uwaga / Notatka

tag Jeśli parametr ma nullwartość , właściwość jest ustawiona TagName na String.Emptywartość .

Dotyczy