HtmlInputCheckBox 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 HtmlInputCheckBox 類別的新執行個體。
public:
HtmlInputCheckBox();
public HtmlInputCheckBox ();
Public Sub New ()
範例
下列程式碼範例示範如何建立和初始化 類別的新實例 HtmlInputCheckBox 。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlInputCheckBox Constructor Sample</title>
<script language="C#" runat="server">
// Create a new instance of HtmlInputCheckBox.
HtmlInputCheckBox cb = new HtmlInputCheckBox();
// Create a new instance of Label.
Label label = new Label();
// Create a new instance of Button.
HtmlButton b = new HtmlButton();
protected void Page_Load(object sender, EventArgs e)
{
// Define attributes of Button and Label.
b.InnerText = "Click";
label.Text = "checkbox";
// Add controls to placeholder
Container.Controls.Add(cb);
Container.Controls.Add(label);
Container.Controls.Add(new LiteralControl("<br />"));
Container.Controls.Add(b);
// Add EventHandler
b.ServerClick += new EventHandler(button_ServerClick);
}
void button_ServerClick(object sender, EventArgs e)
{
switch (cb.Checked)
{
case true:
Message.InnerHtml = "Checkbox is checked.";
break;
default:
Message.InnerHtml = "Checkbox is not checked.";
break;
}
}
</script>
</head>
<body>
<h3>HtmlInputCheckBox Constructor Sample</h3>
<form id="form1" runat="server">
<asp:PlaceHolder id="Container" runat="server"></asp:PlaceHolder>
<br />
<span id="Message"
style="color:red"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlInputCheckBox Constructor Sample</title>
<script language="VB" runat="server">
' Create a new instance of HtmlInputCheckBox.
Dim cb As New HtmlInputCheckBox()
' Create a new instance of Label.
Dim label As New Label()
' Create a new instance of Button.
Dim b As New HtmlButton()
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Define attributes of Button and Label.
b.InnerText = "Click"
label.Text = "checkbox"
' Add controls to placeholder
Container.Controls.Add(cb)
Container.Controls.Add(label)
Container.Controls.Add(New LiteralControl("<br />"))
Container.Controls.Add(b)
' Add EventHandler
AddHandler b.ServerClick, AddressOf button_ServerClick
End Sub
Sub button_ServerClick(ByVal sender As Object, ByVal e As EventArgs)
Select Case cb.Checked
Case True
Message.InnerHtml = "Checkbox is checked."
Case Else
Message.InnerHtml = "Checkbox is not checked."
End Select
End Sub
</script>
</head>
<body>
<h3>HtmlInputCheckBox Constructor Sample</h3>
<form id="Form1" runat="server">
<asp:PlaceHolder id="Container" runat="server"></asp:PlaceHolder>
<br />
<span id="Message"
style="color:red"
runat="server"/>
</form>
</body>
</html>
備註
使用此建構函式來建立和初始化 類別的新實例 HtmlInputCheckBox 。
下表顯示 實例 HtmlInputCheckBox 的初始屬性值。
屬性 | 初始值 |
---|---|
TagName |
「checkbox」 常值字串。 |