Properties
Checked
Text
AutoPostBack
Methods
Focus() –To set the input focus, to a specific checkbox, call this method for that checkbox control.
Events
CheckedChanged – This is fired when the checked status of the check button control is changed.
Here an example to print text in the textbox
WebForm1.aspx :-
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="_12_CheckboxControl.WebForm1" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<fieldset style="width:300px">
<legend><b>Gender</b></legend>
<asp:CheckBox ID="CheckBox1" runat="server" Text="Graduate" />
<br />
<asp:CheckBox ID="CheckBox2" runat="server" Text="PostGraduate" />
<br />
<asp:CheckBox ID="CheckBox3" runat="server" Text="Doctarate" />
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</fieldset>
</div>
</form>
</body>
</html>
WebForm1.aspx.cs :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
namespace _12_CheckboxControl
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
CheckBox1.Focus();
}
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder sbUserChoise = new StringBuilder();
if (CheckBox1.Checked)
sbUserChoise.Append(CheckBox1.Text);
if (CheckBox2.Checked)
sbUserChoise.Append(", "+CheckBox2.Text);
if (CheckBox3.Checked)
sbUserChoise.Append(", " + CheckBox3.Text);
Response.Write("Your Choises " + sbUserChoise.ToString());
}
}
}
No comments:
Post a Comment