.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
sritaa
Sandeep Singh
Melody Anderson
Sharad
Eminent IT

  

CheckBox Control

   
 
     


Introduction :

CheckBox Control is used for selecting predefined (available in CheckBox) value. That means user can be able to select whatever options he/she wants. For eg., it is useful for selecting User hobbies , User Interests etc., ASP.NET CheckBox itself is a class like other controls which are present under System.Web.UI.WebControls namespace.

CheckBox Control is used for selecting predefined (available in CheckBox) value. That means user can be able to select whatever options he/she wants. For eg., it is useful for selecting User hobbies , User Interests etc.,
ASP.NET CheckBox  itself is a class like other controls which are present under System.Web.UI.WebControls namespace.

Important Properties of Asp.NET Webserver  CheckBox control are given below. You can Set /Get these properties  at Design time or at Runtime.

AutoPostBack -  Accept Boolean Value  - If True then page will submit to the server if the index of the dropdown is changed.

CausesValidation -  Accept Boolean Value - Used to Validate the page when Button click event fires.

Enabled - Accept Boolean Value- Used to Get/Set button Enabled

Height - Accept IntergerValue  -  Used to Set/Get height of the textbox

Text - Accept String Value - Used to Define the check box so that user can understand

Width - Accept IntergerValue -  Used to set the width of the Button

Commonly used Events  available in Asp.Net Webserver  CheckBox Control are:

CheckChanged - This event will fire when state of the checkbox is changed.
NOTE:  CheckChanged  event will only fire when AutoPostBack Property of the CheckBox is set to "True";


Lets See an example

Your .aspx code will look like this for a WebServer Control CheckBox

<asp:CheckBox ID="myCheckBox" runat="server" AutoPostBack="True"

            oncheckedchanged="myCheckBox_CheckedChanged" Text="MyCheckBox" />

Full Html Code used in attched example

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!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 runat="server">

    <title>CheckBox Example - DotNetSpark.com</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

   

        <asp:Label ID="lblMessage" runat="server" Text="CheckBox Example"></asp:Label>

        <br />

        <br />

        <asp:CheckBox ID="myCheckBox" runat="server" AutoPostBack="True"

            oncheckedchanged="myCheckBox_CheckedChanged" Text="MyCheckBox" />

        <br />

        <br />

        <asp:Label ID="lblMessageVal" runat="server"></asp:Label>

   

    </div>

    </form>

</body>

</html>


And in the .cs file

protected void myCheckBox_CheckedChanged(object sender, EventArgs e)

{

    lblMessageVal.Text = myCheckBox.Checked.ToString();

} 
Other Tutorials in the same Category:
      
  • CheckBoxList Control      
  • Button Control      
  • Calendar Control      
  • CheckBox Control      
  • DropDownList Control or Combobox      
  • FileUpload Control      
  • Hidden Field Control      
  • ImageButton Control      
  • Link Button Control      
  • ListBox Control      
  • Literal Control      
  • RadioButton Control      
  • RadioButtonList Control      
  • TextBox Control

  •  
         
     
    Return to Main Index Page


    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend