다음을 통해 공유


HtmlGenericControl 생성자

정의

HtmlGenericControl 클래스의 새 인스턴스를 초기화합니다.

오버로드

Name Description
HtmlGenericControl()

기본값을 사용하여 클래스의 새 인스턴스를 HtmlGenericControl 초기화합니다.

HtmlGenericControl(String)

지정된 태그를 사용하여 클래스의 HtmlGenericControl 새 인스턴스를 초기화합니다.

HtmlGenericControl()

기본값을 사용하여 클래스의 새 인스턴스를 HtmlGenericControl 초기화합니다.

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

예제

다음 코드 예제에서는 매개 변수 없는 생성자를 사용 하 여 클래스의 HtmlGenericControl 새 인스턴스를 만드는 방법을 보여 줍니다.

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

설명

이 생성자를 사용하여 기본값을 사용하여 클래스의 새 인스턴스를 HtmlGenericControl 만들고 초기화합니다. 일반적으로 서버 쪽 <span> 요소를 동적으로 만드는 데 사용됩니다.

다음 표에서는 인스턴스에 대한 초기 속성 값을 보여 줍니다 HtmlGenericControl.

재산 초기 값
TagName "span" 리터럴 문자열입니다.

적용 대상

HtmlGenericControl(String)

지정된 태그를 사용하여 클래스의 HtmlGenericControl 새 인스턴스를 초기화합니다.

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)

매개 변수

tag
String

클래스의 이 인스턴스가 만들어지는 요소의 이름입니다.

예제

다음 코드 예제에서는 오버로드된 생성자를 사용하여 클래스의 HtmlGenericControl 새 인스턴스를 만드는 방법을 보여 줍니다.

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

설명

이 생성자를 사용하여 지정된 태그를 사용하여 클래스의 새 인스턴스를 HtmlGenericControl 만들고 초기화합니다. 이렇게 하면 .NET Framework 클래스로 직접 표현되지 않는 HTML 서버 컨트롤 요소를 동적으로 만들 수 있습니다.

다음 표에서는 인스턴스에 대한 초기 속성 값을 보여 줍니다 HtmlGenericControl.

재산 초기 값
TagName 매개 변수의 값입니다 tag .

메모

매개 변수가 tagnull있으면 속성이 TagName .로 String.Empty설정됩니다.

적용 대상