HtmlGenericControl Konstruktor
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menginisialisasi instans baru kelas HtmlGenericControl.
Overload
| HtmlGenericControl() |
Menginisialisasi instans HtmlGenericControl baru kelas dengan nilai default. |
| HtmlGenericControl(String) |
Menginisialisasi instans HtmlGenericControl baru kelas dengan tag yang ditentukan. |
HtmlGenericControl()
Menginisialisasi instans HtmlGenericControl baru kelas dengan nilai default.
public:
HtmlGenericControl();
public HtmlGenericControl();
Public Sub New ()
Contoh
Contoh kode berikut menunjukkan cara membuat instans HtmlGenericControl baru kelas menggunakan konstruktor tanpa parameter.
<%@ 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>
Keterangan
Gunakan konstruktor ini untuk membuat dan menginisialisasi instans HtmlGenericControl baru kelas menggunakan nilai default. Biasanya digunakan untuk membuat elemen sisi <span> server secara dinamis.
Tabel berikut ini memperlihatkan nilai properti awal untuk instans HtmlGenericControl.
| Properti | Nilai Awal |
|---|---|
TagName |
String harfiah "rentang". |
Berlaku untuk
HtmlGenericControl(String)
Menginisialisasi instans HtmlGenericControl baru kelas dengan tag yang ditentukan.
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
Nama elemen tempat instans kelas ini dibuat.
Contoh
Contoh kode berikut menunjukkan cara membuat instans HtmlGenericControl baru kelas menggunakan konstruktor yang kelebihan beban.
<%@ 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>
Keterangan
Gunakan konstruktor ini untuk membuat dan menginisialisasi instans HtmlGenericControl baru kelas menggunakan tag yang ditentukan. Ini memungkinkan Anda untuk secara dinamis membuat elemen kontrol server HTML apa pun yang tidak secara langsung diwakili oleh kelas .NET Framework.
Tabel berikut ini memperlihatkan nilai properti awal untuk instans HtmlGenericControl.
| Properti | Nilai Awal |
|---|---|
TagName |
Nilai tag parameter . |
Catatan
tag Jika parameter adalah null, TagName properti diatur ke String.Empty.