Asp. NET checkbox check box control Use _ Base application

Source: Internet
Author: User

We can use two types of ASP.net controls to add a check box to a Web forms page: A separate CheckBox control or a CheckBoxList control. Both controls provide a way for the user to enter Boolean data (TRUE or FALSE, yes or no).

Here we use the checkbox alone and look at its properties first

Property Description . NET
AutoPostBack Specify whether the form will be returned to the server immediately after the Checked property has changed. The default is False. 1.0
CausesValidation Specify whether to perform validation when clicking the Button control. 2.0
Checked Specify whether the check box is selected. 1.0
Inputattributes The collection of property names and values used by the Input element of the CheckBox control. 2.0
Labelattributes A collection of property names and values used by the Label element of the CheckBox control. 2.0
Runat Specify that the control is a server control. Must be set to "server". 1.0
Text The text label associated with the check box. 1.0
TextAlign The alignment of the text label associated with the check box. (right or left) 1.0
ValidationGroup The group of controls to validate when a CheckBox control is sent back to the server. 2.0
OnCheckedChanged The name of the function to be executed when the Checked property is changed.

Let's do a simple example to illustrate

Foreground code:

<%@ Page language= "C #" autoeventwireup= "true" codefile= "CheckBox.aspx.cs" inherits= "Webcontrols_checkbox"%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

Background code:

Using System;
Using System.Collections.Generic;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;

public partial class WebControls_CheckBox:System.Web.UI.Page
{
 protected void Page_Load (object sender, EventArgs e)
 {

 }
 protected void btnSubmit_Click (object sender, EventArgs e)
 {
 Lblstate.text = String. Empty;
 if (chksport.checked)
 {
  Lblstate.text = Lblstate.text + chksport.text;
 }
 if (chksport2.checked)
 {
  if (lblState.Text.Length = = 0)
  {
  lblstate.text = Chksport2.text;
  }
  Else
  {
  Lblstate.text = Lblstate.text + "," + Chksport2.text;
  }}
 if (chksport3.checked)
 {
  if (lblState.Text.Length = = 0)
  {
  lblstate.text = Chksport2.text;
  }
  Else
  {
  Lblstate.text = Lblstate.text + ', ' + Chksport3.text;
  }
 }
 }
}

Operation Effect:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.