How to use CheckBox control in asp.net

How to use CheckBox control in asp.net (use of checkbox checkchange function):



CheckBox control is an asp.net predefined web control present in .net platform. if we want to determine whether checkbox is checked then we need to use the checkbox Checked property.  For this we use this Property and check that given checkbox is checked or not. 

Other asp.net checkbox related post:



These Examples considered in this asp.net tutorial for describing to type of using checkbox in asp.net.
Now we consider one more example in this we take two checkbox controls and one label control on the web page.

Checkbox checkchenge function:


Here we create a function of checkbox for this take checkbox with id chbox. The function is .
protected void Chbox_CheckChanged(object sender, System.EventArgs e)
    {

        Response.Write("Asp.net developer: ");
        if (Chbox.Checked == true)
        {
            Label1.Text = "yes i am working";
            Chbox2.Checked = true;
        }
        else
        {
            Label1.Text = "No i am not working";
            Chbox2.Checked = false;
        }
    } 

Code of asp.net checkbox control.aspx  page :


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="checkbox control.aspx.cs"
    Inherits="checkbox_control" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server"> 
    protected void Chbox_CheckChanged(object sender, System.EventArgs e)
    {

        Response.Write("Asp.net developer: ");
        if (Chbox.Checked == true)
        {
            Label1.Text = "yes i am working";
            Chbox2.Checked = true;
        }
        else
        {
            Label1.Text = "No i am not working";
            Chbox2.Checked = false;
        }
    } 
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>CheckBox example: how to use CheckBox control in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center" style="font-family: Arial, Helvetica, sans-serif; font-size: x-large;
        font-weight: 700">
        <h1>
            Example of Checkbox on asp.net page
            <br />
            to check this is selected or not
        </h1>
        <asp:Label ID="Label1" runat="server"></asp:Label>
        <hr />
        <asp:CheckBox ID="Chbox" runat="server" Text="Are you working with asp.net " OnCheckedChanged="Chbox_CheckChanged"
            AutoPostBack="true" />
        <br />
        <br />
        <asp:CheckBox ID="Chbox2" runat="Server" Text="Check Box auto checked " TextAlign="Left" />
    </div>
    <hr />
    </form>
</body>
</html> 
 
How to check If checkbox Is checked in asp.net
Example of How to use CheckBox control in asp.net


Other Asp.net web controls related Post:


Comments