HtmlInputCheckBox Constructor
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the HtmlInputCheckBox class.
public:
HtmlInputCheckBox();
public HtmlInputCheckBox ();
Public Sub New ()
Examples
The following code example demonstrates how to create and initialize a new instance of the HtmlInputCheckBox class.
<%@ 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>
Remarks
Use this constructor to create and initialize a new instance of the HtmlInputCheckBox class.
The following table shows the initial property value for an instance of HtmlInputCheckBox.
Property | Initial Value |
---|---|
TagName |
The "checkbox" literal string. |
Applies to
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기