Sep 01 2009

asp.net checkbox control

The asp.net checkBox controls have an option to select or deselect
select means yes or true
Deselect means no or false

<asp:CheckBox ID=”CheckBox1″ runat=”server” Text=”Agree” />


Main Properties of CheckBox

Checked : whether checkbox is checked or not

OnCheckedChanged : when checkbox event is chanaged to be executed

AutopostBack : to activate OnCheckedChanged event make AutoPostBack         property is True

Text:
text appear next to the checkbox

How to check CheckBox is checked or not

if checkBox is checked then textbox1 display “He agree to terms and conditions.

If checkBox is not checked then textbox1 displays “He has not agree to terms and conditions.

Sample code:

In Default.aspx page

<div>
<asp:CheckBox ID=”CheckBox1″ runat=”server” Text=”Agree” />
<br />
<asp:TextBox ID=”TextBox1″ runat=”server” Width=”300px”></asp:TextBox>
<br />
<asp:Button ID=”Button1″ runat=”server” Text=”Button” onclick=”Button1_Click” />
</div>

In Default.aspx.cs page (Button Double click)

protected void Button1_Click(object sender, EventArgs e)
{
if (CheckBox1.Checked)
{
TextBox1.Text = “he ” + CheckBox1.Text + ” terms and condition”;
}
else
{
TextBox1.Text = “he has not ” + CheckBox1.Text + ” terms and condition”;
}
}

Getting asp.net CheckBox value into string

string chBoxItem = CheckBox1.Text;

Happy coding…

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Leave a Reply

Alibi3col theme by Themocracy