ASP .NET CheckBox Control



CheckBox

  • The CheckBox control is used to display a check box.
Property
Description
AutoPostBack
A Boolean value that specifies whether the form should be posted immediately after the Checked property has changed or not. Default is false
Checked
A Boolean value that specifies whether the check box is checked or not
id
A unique id for the control
OnCheckedChanged
The name of the function to be executed when the Checked property has changed
runat
Specifies that the control is a server control.  Must be set to "server"
Text
The text next to the check box
TextAlign
On which side of the check box the text should appear (right or left)



Example Code :
 
<script  runat="server">
   Sub Check(sender As Object, e As EventArgs)
     if check1.Checked then
          work.Text=home.Text
     else
          work.Text=""
     end if
   End Sub
</script>

<html>
<body>
<form runat="server">
<p>Home Phone: <asp:TextBox id="home" runat="server" />
<br />Work Phone:<asp:TextBox id="work" runat="server" />
<asp:CheckBox id="check1" Text="Same as home phone" TextAlign="Right" AutoPostBack="True" OnCheckedChanged="Check" runat="server" />
</p>
</form>
</body>
</html>

In above code two texbox one for home phone and second for work phone ....and one check box 

When we enter home phone and check box check then due to auto post back   Check() event call and home phone no copy into work phone no....

 



Comments

Popular posts from this blog

Delete Confirmation for Delete ButtonField, TemplateField and CommandField in a GridView in ASP.NET

Selecting/Deselecting all CheckBoxes inside a ListView In ASP.NET

Remove Duplicate Chars From String