Asp.net Check Box control

asp:CheckBox control
CheckBox control is used to give option to the user.

Preferably CheckBox control is utilized to offer alternative to the client. When it is rendered on the page, it is executed through <input type=checkbox></input> HTML tag. Its properties like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height and so on are actualized through style properites of <input>. You can set its Text property either by setting Text properties in the .aspx page or from server side page. (different properties can likewise be set from the two pages)

Following are some important properties that are very useful.
AutoPostBackForm is automatically posted back when CheckBox is checked or Unchecked.
CausesValidationtrue/false. If true, Form is validated if Validation control has been used in the form.
Checkedtrue/false. If true, Check box is checked by default.
OnCheckedChangedFires when CheckBox is checked or Unchecked. This works only if AutoPostBack property is set to true.
ValidationGroupUsed to put a checkbox under a particular validation group. It is used when you have many set of form controls and by clicking a paricular button you want to validate a particular set of controls only.


  
  
Ex. 

// CheckBox control
                        <asp:CheckBox ID="checkbox2" runat="Server" Text="Click, if Office address is same as Home address" AutoPostBack="True" OnCheckedChanged="PutHomeAddressAsOfficeAddress" BorderColor="brown" BorderWidth="1" CausesValidation="True" />
                        
                        // Fires when CheckBox is clicked(checked) or unchecked
                        protected void PutHomeAddressAsOfficeAddress(object sender, EventArgs e)
                        {
                            if (checkbox1.Checked)
                            {
                                TextBox2.Text = TextBox1.Text;
                                Label1.Text = "Notice: Home address has been written into Office TextBox too.";
                            }
                            else
                            {
                                TextBox2.Text = "";
                                Label1.Text = "Notice: Office address is empty now.";
                            }
                        }
    

                    




Share on Google Plus

About It E Research

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment