HtmlGenericControl Oluşturucular

Tanım

HtmlGenericControl sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

HtmlGenericControl()

HtmlGenericControl sınıfının yeni bir örneğini varsayılan değerlerle başlatır.

HtmlGenericControl(String)

Belirtilen etiketle sınıfının yeni bir örneğini HtmlGenericControl başlatır.

HtmlGenericControl()

HtmlGenericControl sınıfının yeni bir örneğini varsayılan değerlerle başlatır.

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

Örnekler

Aşağıdaki kod örneği, parametresiz oluşturucu kullanarak sınıfın HtmlGenericControl yeni bir örneğinin nasıl oluşturulacağını gösterir.

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

Açıklamalar

Varsayılan değerleri kullanarak sınıfın HtmlGenericControl yeni bir örneğini oluşturmak ve başlatmak için bu oluşturucuyu kullanın. Genellikle dinamik olarak bir sunucu tarafı <span> öğesi oluşturmak için kullanılır.

Aşağıdaki tabloda, örneğinin ilk özellik değerleri gösterilmektedir HtmlGenericControl.

Özellik İlk Değer
TagName "span" değişmez değeri dizesi.

Şunlara uygulanır

HtmlGenericControl(String)

Belirtilen etiketle sınıfının yeni bir örneğini HtmlGenericControl başlatır.

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)

Parametreler

tag
String

Sınıfın bu örneğinin oluşturulduğu öğenin adı.

Örnekler

Aşağıdaki kod örneği, aşırı yüklenmiş oluşturucuyu kullanarak sınıfın HtmlGenericControl yeni bir örneğinin nasıl oluşturulacağını gösterir.

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

Açıklamalar

Belirtilen etiketi kullanarak sınıfın HtmlGenericControl yeni bir örneğini oluşturmak ve başlatmak için bu oluşturucuyu kullanın. Bu, doğrudan bir .NET Framework sınıfı tarafından temsil edilmeyen herhangi bir HTML sunucusu denetim öğesini dinamik olarak oluşturmanıza olanak tanır.

Aşağıdaki tabloda, örneğinin ilk özellik değerleri gösterilmektedir HtmlGenericControl.

Özellik İlk Değer
TagName parametresinin tag değeri.

Not

tag parametresi ise nullTagName özelliği olarak String.Emptyayarlanır.

Şunlara uygulanır