Wednesday 8 October 2014

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

CheckBox Use Terms and Conditions

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 Asp.net c#.

If Checkbox Checked = True    Agreed 

If Checkbox  Checked = False  Not Agreed



                         DEMO






                            
                               Html Coding


 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
    <title></title>    
      </head>
   <body>
    <form id="form1" runat="server">
    <div>              
          <table>

            <tr><td>
                <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
                </td><td>
                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                </td></tr>
               <tr><td>
                <asp:Label ID="Label2" runat="server" Text="Mobile"></asp:Label>
                </td><td>
                    <asp:TextBox ID="txtMobile" runat="server"></asp:TextBox>
                </td></tr>
            <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"  />
                </td></tr>
                           
        </table>
    </div>
    </form>
</body>

</html>


                       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);
        con.Open();

    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSave_Click(object sender, EventArgs e)
    {

        dbcon();

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

    }

}




Html Coding

 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
    <title></title>     
      </head>
   <body>
    <form id="form1" runat="server">
    <div>               
          <table>

            <tr><td>
                <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
                </td><td>
                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                </td></tr>
               <tr><td>
                <asp:Label ID="Label2" runat="server" Text="Mobile"></asp:Label>
                </td><td>
                    <asp:TextBox ID="txtMobile" runat="server"></asp:TextBox>
                </td></tr>
            <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"  />
                </td></tr>
                            
        </table>
    </div>
    </form>
</body>

</html>

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);
        con.Open();

    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
   
 protected void btnSave_Click(object sender, EventArgs e)
       
       {

        dbcon();

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

    }
}














                                     i think useful this post.

0 comments:

Post a Comment