Validation to Check Terms and Conditions Checkbox Checked or Not Using Asp.Net C#


Validation for terms and conditions checkbox checked or  not  check terms and conditions checkbox selected or not using c# or restrict user to accept terms and conditions using c#.

If Checkbox Checked = True    Agreed 

If Checkbox  Checked = False  Not Agreed


Html Coding

 <html xmlns="">
    <form id="form1" runat="server">

                <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                <asp:Label ID="Label2" runat="server" Text="Mobile"></asp:Label>
                    <asp:TextBox ID="txtMobile" runat="server"></asp:TextBox>
            <tr><td> Check Status:</td><td>
                <asp:CheckBox ID="ChkTermsCondition" runat="server" />
          Agree Terms & Conditions</td></tr>
            <tr><td></td><td><asp:Button ID="btnSave" runat="server" Text="Check"  />


                       C# Coding

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Termss : System.Web.UI.Page
    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter adp;
    SqlDataReader rd;
    DataSet ds;
    string query;

    public void dbcon()
        string connn = (System.Configuration.ConfigurationManager.ConnectionStrings["dbcon"].ToString());
        con = new SqlConnection(connn);


    protected void Page_Load(object sender, EventArgs e)


    protected void btnSave_Click(object sender, EventArgs e)


        if (ChkTermsCondition.Checked == true)
            query = "insert into terms(name,mobile)values('" + txtName.Text + "' ,'" + txtMobile.Text + "')";
            cmd = new SqlCommand(query, con);
            Response.Write("<script>alert('Terms & Condition Accepted')</script>");
            Response.Write("<script>alert('Please Select Terms & Condition')</script>");



First Add - New Web Form - Select Labels & TextBoxs  & CheckBox & Button - Textbox Id Change(Required)

Next -  Checkbox  Id Change(Required)

Next - Button Id - Change (Required)

Next - Create Table(terms) -  Add Two Fields 

Next - Double Click  Check Button


Next -  Add - NameSpaces  &  DataBase Connection  for Table Access

Next -  Write Coding For Checkbox Condition Check  After  Insert Query 

Next - F5 Click - Run the Program -  Enter Textbox Values - Click - Check  Button & Checkbox UnSelect

PopUp - Show  - Select Terms & Condition

Enter Textbox Values - Click - Check  Button & Checkbox Select

PopUp Show - Agreed Terms & Condition  &  Insert  Textbox Values

DataBase Table(terms)  Inserted Values



Post a Comment