2016-09-26



CheckBox is an asp.net web server control. checkbox allow web site visitor to select (checked) a true or false condition. so the checkbox control create a checkbox on web forms page which allow user to switch between a true or false state. checkbox Text property create a caption for it. we can left or right align caption by using checkbox TextAlign property.

the checkbox control has many properties that help us to change looks and style such as ForeColor, BorderColor, BackColor, BorderStyle, BorderWidth, CssClass, EnableTheming, Font, Height, SkinID, ToolTip, Width etc.

if we want to determine whether checkbox is checked (selected) then we need to test the checkbox Checked property. checkbox AutoPostBack property value true enable automatic posting to server. checkbox CheckedChanged event raised when someone change the checkbox true or false state. .net developers can write an event handler for CheckedChanged event. using CheckedChanged event we can know the checkbox current state and can perform any task when page post to server.

the following example demonstarte us how to use checkbox control in asp.net. here we create a web form with a Label and two checkbox control. when someone check the first checkbox then the label show a message that he checked first checkbox. the second checkbox programmatically checked when user checked the first checkbox.

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
protected void CheckBox1_CheckChanged(object sender, System.EventArgs e) {

if (CheckBox1.Checked == true) {
Label1.Text = "WOW! You are a member of an asp.net user group.";
Label1.ForeColor = System.Drawing.Color.Green;
}
else{
Label1.Text = "You are not a member of any asp.net user group.";
Label1.ForeColor = System.Drawing.Color.Crimson;
}
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How to use CheckBox control in asp.net</title>
</head>

<body style="padding:25px">
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
How to use CheckBox control
</h2>
<hr width="450" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Bold="true"
Font-Names="Comic Sans MS"
ForeColor="Crimson"
Font-Italic="true"
Font-Size="X-Large"
Width="350"
/>
<br /><br />
<asp:CheckBox
ID="CheckBox1"
runat="server"
Text="Are you an asp.net user group member?"
OnCheckedChanged="CheckBox1_CheckChanged"
AutoPostBack="true"
Font-Names="Serif"
Font-Size="X-Large"
/>
</div>
</form>
</body>
</html>

Best ASP.NET Hosting Recommendation

ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers ASP.NET hosting starts from $1/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable ASP.NET Hosting, ASPHostPortal.com should be your best choice.

Show more