CheckBox Server Control 
CheckBox controls user to check the mandatory or optional checkbox depending on the requirement.
CheckBox code: without AutopostBack property. When there is an option that user should select the Terms and conditions before submitting the form.
.aspx
<form id="form1" runat="server">
  <div>
    <asp:CheckBox ID="CheckBox1" runat="server" Text="I accept the terms and conditions" />
    <br />
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    <br />
    <br />
    <asp:Label ID="Label1" runat="server"></asp:Label>
  </div>
</form>
.cs
protected void Button1_Click(object sender, EventArgs e)
    {
        if (CheckBox1.Checked)
        {
            Label1.Text = "CheckBox1 am checked";
        }
        else
        {
            Label1.Text = "Please Accept the terms and conditions to Continue";
        }
    }
CheckBox code: When user selects the checkbox then an event called. 
.aspx
<form id="form1" runat="server">
    <div>
        <asp:CheckBox ID="CheckBox1" AutoPostBack="true" runat="server" 
            Text="Donate 10$ to CoolTuts" oncheckedchanged="CheckBox1_CheckedChanged" />
        <br />
        <br />
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </div>
    </form>
.cs
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (CheckBox1.Checked)
            Label1.Text = "Thanks for your donation";
        else
            Label1.Text = String.Empty;
    }
ASP Standard Controls
- ASP Label Control
- ASP TextBox Control
- ASP Button Control
- ASP Link Button Control
- ASP ImageButton Control
- ASP HyperLink Control
- ASP DropDownList Control
- ASP ListBox Control
- ASP CheckBox Control
- ASP CheckBoxList Control
- ASP RadioButton Control
- ASP RadioButtonList Control
- ASP Image Control
- ASP ImageMap Control
- ASP Calendar Control
- ASP Table Control
- ASP BulletedList Control
- ASP Hidden Control
- ASP Literal Control
- ASP AdRotator Control
- ASP Panel Control
- ASP PlaceHolder Control
- ASP FileUpload Control
- ASP UserControl
- ASP Custom Control
Random Tips and Tricks
Monday, September 20, 2010
Subscribe to:
Post Comments (Atom)
 

0 comments:
Post a Comment