Forms

Registration Form 

----------------
ASPX Code
----------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Form.aspx.cs" Inherits="Form" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Form</title>
    <meta charset="utf-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"/>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
    <style type="text/css">
        .container{
            margin-bottom: 30px;
        }
        .col-md-6{
            margin: 0 auto;
            box-shadow: 2px 4px 10px rgba(0, 0, 0, 0.1), 3px 6px 10px rgba(0, 0, 0, 0.2);
            padding: 20px 30px;
        }
        h2{
            padding: 20px 0px;
        }
    </style>
    </head>
<body style="background-color:antiquewhite">
        <div class="container">
        <h2 class="text-center">GreenLight </h2>
            <form id="form1" runat="server">
                <div class="col-md-6">
                    
                    
                    <asp:Label ID="Label1" runat="server" Text="Full Name"></asp:Label>
                    <div class="form-control-file">
                   <%-- <div class="form-group input-group">  --%>  
                    <asp:TextBox ID="txtfirstName" runat="server" CssClass="form-control" required=""></asp:TextBox>  
                        <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter Name" ControlToValidate="txtfirstName" Font-Bold="True" ForeColor="Red">
                            </asp:RequiredFieldValidator></td></tr></table>
                    </div>                        
                    

                     <asp:Label ID="Label5" runat="server" Text="Address"></asp:Label>
                     <div class="form-control-file">
                     <%--<div class="form-group input-group">--%>
                     <asp:TextBox ID="txtAddress" runat="server" CssClass="form-control"  TextMode="MultiLine" required=""></asp:TextBox>
                         <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Enter Address" ControlToValidate="txtAddress" Font-Bold="True" ForeColor="Red"></asp:RequiredFieldValidator></td></tr></table>
                     </div>

                     <asp:Label ID="Label2" runat="server" Text="Pan No"></asp:Label>
                     <div class="form-control-file">
                     <%--<div class="form-group input-group">--%>    
                     <asp:TextBox ID="txtpan" runat="server" CssClass="form-control" MinLength="10"  MaxLength="10" required=""></asp:TextBox>
                         <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Enter Pan " ControlToValidate="txtpan" Font-Bold="True" ForeColor="Red"></asp:RequiredFieldValidator></td></tr></table>
                     </div>  

                     <asp:Label ID="Label12" runat="server" Text="Aadhar No"></asp:Label>
                     <div class="form-control-file">
                    <%-- <div class="form-group input-group">  --%>  
                     <asp:TextBox ID="txtaadar" runat="server" CssClass="form-control" MinLength="12"  MaxLength="12" required=""></asp:TextBox>
                         <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Enter Aadhaar" ControlToValidate="txtaadar" Font-Bold="True" ForeColor="Red"></asp:RequiredFieldValidator></td></tr></table>
                     </div>

                     <asp:Label ID="Label7" runat="server" Text="Mobile"></asp:Label>
                     <div class="form-control-file">
                    <%-- <div class="form-group input-group">--%>
                     <asp:TextBox ID="txtPhone" runat="server" CssClass="form-control" MinLength="10"  MaxLength="10" required=""></asp:TextBox>
                         <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="Enter Mobile" ControlToValidate="txtPhone" Font-Bold="True" ForeColor="Red"></asp:RequiredFieldValidator></td></tr></table>
                     </div>
                    
                     <asp:Label ID="Label8" runat="server" Text="Email"></asp:Label>
                     <div class="form-control-file">
                     <%--<div class="form-group input-group">--%>
                     <asp:TextBox ID="txtEmail" runat="server" CssClass="form-control"  required=""></asp:TextBox>
                          <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator15" runat="server" ErrorMessage="Enter Email" ControlToValidate="txtEmail" Font-Bold="True" ForeColor="Red" Display="Dynamic"></td>
                                <td><asp:RegularExpressionValidator ID="RegularExpressionValidator1" ValidationExpression="^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$" runat="server" ControlToValidate="txtEmail" Font-Bold="true" Display="Dynamic" ErrorMessage="Inavlid Email"></asp:RegularExpressionValidator></td>
                            </asp:RequiredFieldValidator></tr></table>
                     </div>                                                            

                     <asp:Label ID="Label9" runat="server" Text="State"></asp:Label>
                     <div class="form-control-file">
                     <%--<div class="form-group input-group">--%>
                  <asp:DropDownList ID="DDLState" InitialValue="Select State" runat="server" CssClass="form-control" AutoPostBack="True">
                  <asp:ListItem>Select State</asp:ListItem>
                  <asp:ListItem>Andhra Pradesh</asp:ListItem>
                  <asp:ListItem>Arunachal Pradesh</asp:ListItem>
                  <asp:ListItem>Assam</asp:ListItem>
                  <asp:ListItem>Bihar</asp:ListItem>
                  <asp:ListItem>Chhattisgarh</asp:ListItem>
                  <asp:ListItem>Goa</asp:ListItem>
                  <asp:ListItem>Gujarat</asp:ListItem>
                  <asp:ListItem>Haryana</asp:ListItem>
                  <asp:ListItem>Himachal Pradesh</asp:ListItem>
                  <asp:ListItem>Jammu and Kashmir</asp:ListItem>
                  <asp:ListItem>Jharkhand</asp:ListItem>
                  <asp:ListItem>Karnataka</asp:ListItem>
                  <asp:ListItem>Kerala</asp:ListItem>
                  <asp:ListItem>Madhya Pradesh</asp:ListItem>
                  <asp:ListItem>Maharashtra</asp:ListItem>
                  <asp:ListItem>Manipur</asp:ListItem>
                  <asp:ListItem>Meghalaya</asp:ListItem>
                  <asp:ListItem>Mizoram</asp:ListItem>
                  <asp:ListItem>Nagaland</asp:ListItem>
                  <asp:ListItem>Odisha</asp:ListItem>
                  <asp:ListItem>Punjab</asp:ListItem>
                  <asp:ListItem>Rajasthan</asp:ListItem>
                  <asp:ListItem>Sikkim</asp:ListItem>
                  <asp:ListItem>Tamil Nadu</asp:ListItem>
                  <asp:ListItem>Telangana</asp:ListItem>
                  <asp:ListItem>Tripura</asp:ListItem>
                  <asp:ListItem>Uttar Pradesh</asp:ListItem>
                  <asp:ListItem>Uttarakhand</asp:ListItem>
                  <asp:ListItem>West Bengal</asp:ListItem>
              </asp:DropDownList>
                         <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="Select State" ControlToValidate="txtfirstName" Font-Bold="True" ForeColor="Red">
                            </asp:RequiredFieldValidator></td></tr></table>
          </div>

                     <asp:Label ID="Label10" runat="server" Text="District"></asp:Label>
                      <div class="form-control-file">
                     <%--<div class="form-group input-group">--%>
                     <asp:TextBox ID="txtdistrict" runat="server" CssClass="form-control" required=""></asp:TextBox>
                         <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ErrorMessage="Enter District" ControlToValidate="txtfirstName" Font-Bold="True" ForeColor="Red">
                            </asp:RequiredFieldValidator></td></tr></table>
                     </div>

                      <asp:Label ID="Label3" runat="server" Text="Taluka"></asp:Label>
                       <div class="form-control-file">
                     <%-- <div class="form-group input-group">--%>
                      <asp:TextBox ID="txttaluka" runat="server" CssClass="form-control"  required=""></asp:TextBox>
                          <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ErrorMessage="Enter Taluka" ControlToValidate="txtfirstName" Font-Bold="True" ForeColor="Red">
                            </asp:RequiredFieldValidator></td></tr></table>
                      </div>

                    <asp:Label ID="Label4" runat="server" Text="Village"></asp:Label>
                     <div class="form-control-file">
                     <%--<div class="form-group input-group">--%>
                    <asp:TextBox ID="txtvillage" runat="server" CssClass="form-control"  required=""></asp:TextBox>
                        <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ErrorMessage="Enter Village" ControlToValidate="txtfirstName" Font-Bold="True" ForeColor="Red">
                            </asp:RequiredFieldValidator></td></tr></table>
                    </div>

                       <asp:Label ID="Label6" runat="server" Text="Pin"></asp:Label>
                        <div class="form-control-file">
                      <%-- <div class="form-group input-group">--%>
                       <asp:DropDownList ID="DropDownList1" InitialValue="Select Pin Code" runat="server" CssClass="form-control" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                           <asp:ListItem>Select Pin Code</asp:ListItem>
                           <asp:ListItem>1</asp:ListItem>
                           <asp:ListItem>2</asp:ListItem>
                           <asp:ListItem>3</asp:ListItem>
                           <asp:ListItem>4</asp:ListItem>
                           <asp:ListItem>5</asp:ListItem>
                       </asp:DropDownList> 
                                       
                            <asp:TextBox ID="txt1" CssClass="form-control" runat="server" AutoPostBack="True" Visible="TRUE"></asp:TextBox>
                            <asp:TextBox ID="txt2" CssClass="form-control" runat="server" AutoPostBack="True" Visible="TRUE"></asp:TextBox>
                            <asp:TextBox ID="txt3" CssClass="form-control" runat="server" AutoPostBack="True" Visible="TRUE"></asp:TextBox>
                            <asp:TextBox ID="txt4" CssClass="form-control" runat="server" AutoPostBack="True" Visible="TRUE"></asp:TextBox>
                            <asp:TextBox ID="txt5" CssClass="form-control" runat="server" AutoPostBack="True" Visible="TRUE"></asp:TextBox>
                           <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ErrorMessage="Select Pin Code" ControlToValidate="txtfirstName" Font-Bold="True" ForeColor="Red">
                            </asp:RequiredFieldValidator></td></tr></table>
                       <%--<asp:TextBox ID="txtPin" runat="server" CssClass="form-control" placeholder="Enter the Pin" MaxLength="6" required=""></asp:TextBox>--%>
                       </div>

                     <asp:Label ID="Label11" runat="server" Text="Ref Person Name"></asp:Label>
                     <div class="form-control-file">
                     <%--<div class="form-group input-group">    --%>
                     <asp:TextBox ID="txtrpn" runat="server" CssClass="form-control"  required=""></asp:TextBox>
                         <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ErrorMessage="Enter Name" ControlToValidate="txtfirstName" Font-Bold="True" ForeColor="Red">
                            </asp:RequiredFieldValidator></td></tr></table>
                     </div>  

                     <asp:Label ID="Label13" runat="server" Text="Ref Person Mobile"></asp:Label>
                     <div class="form-control-file">
                    <%-- <div class="form-group input-group">--%>    
                     <asp:TextBox ID="txtrpm" runat="server" MaxLength="10" MinLength="10" CssClass="form-control" required=""></asp:TextBox>
                         <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" ErrorMessage="Enter Mobile" ControlToValidate="txtfirstName" Font-Bold="True" ForeColor="Red">
                            </asp:RequiredFieldValidator></td></tr></table>
                     </div>  

                     <asp:Label ID="Label14" runat="server" Text="Family Member Name"></asp:Label>
                     <div class="form-control-file">
                    <%-- <div class="form-group input-group">    --%>
                     <asp:TextBox ID="txtfmn" runat="server" CssClass="form-control" required=""></asp:TextBox>
                         <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" ErrorMessage="Enter Member Name" ControlToValidate="txtfirstName" Font-Bold="True" ForeColor="Red">
                            </asp:RequiredFieldValidator></td></tr></table>
                     </div>  

                     <asp:Label ID="Label15" runat="server" Text="Family Mobile No"></asp:Label>
                     <div class="form-control-file">
                     <%--<div class="form-group input-group"> --%>   
                     <asp:TextBox ID="txtfmm" runat="server" MaxLength="10" MinLength="10" CssClass="form-control" required=""></asp:TextBox>
                         <table><tr><td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator14" runat="server" ErrorMessage="Enter Number" ControlToValidate="txtfirstName" Font-Bold="True" ForeColor="Red">
                            </asp:RequiredFieldValidator></td></tr></table>
                     </div>  


                     <%--<div class="button-group">
                     <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" Text="I would like to attend ETI training and please send the details on above mail and I'm ready to pay training fees of Rs 500/-" />
                     </div>--%>


                <div class="button-group">
                <asp:Button ID="btnRegister" runat="server" Text="Register" CssClass="btn btn-success" OnClick="btnRegister_Click" Enabled="True" /><br /><br />
               <%-- <asp:Button ID="btnClear" runat="server" Text="Clear" CssClass="btn btn-danger" />--%>
               
                     </div>&nbsp;<asp:Label ID="lblsuccess" runat="server"></asp:Label>
          
                     <asp:Label ID="lblwarning" runat="server"></asp:Label>
                     </div>
                     <div><marquee><h2>ETI Infosystems</h2></marquee></div>       
          </form>
     </div>
</body>
</html>


---------------
Aspx.cs Code
---------------

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;
using System.Web.Script;

public partial class Form : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-UEBS4LM;Initial Catalog=Grapes;User ID=sa;Password=eti");

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnRegister_Click(object sender, EventArgs e)
    {
        {
            try
            {
                con.Open();
                if (txtfirstName.Text != "" && txtAddress.Text != "" && txtpan.Text != "" && txtaadar.Text != "" && txtPhone.Text != "" && txtEmail.Text != "" && DDLState.Text != "" && txtdistrict.Text != "" && txttaluka.Text != "" && txtvillage.Text != "" && DropDownList1.Text != "" && txt1.Text != "" && txt2.Text != "" && txt3.Text != "" && txt4.Text != "" && txt5.Text != "" && txtrpn.Text != "" && txtrpm.Text != "" && txtfmn.Text != "" && txtfmm.Text != "")
                {
                    SqlCommand cmd = new SqlCommand("Insert into GreeeLight values('" + txtfirstName.Text.ToString() + "','" + txtAddress.Text.ToString() + "','" + txtpan.Text.ToString() + "','" + txtaadar.Text.ToString() + "','" + txtPhone.Text.ToString() + "','" + txtEmail.Text.ToString() + "','" + DDLState.Text.ToString() + "','" + txtdistrict.Text.ToString() + "','" + txttaluka.Text.ToString() + "','" + txtvillage.Text.ToString() + "',,'" + DropDownList1.Text.ToString() + "','" + txt1.Text.ToString() + "','" + txt2.Text.ToString() + "','" + txt3.Text.ToString() + "','" + txt4.Text.ToString() + "','" + txt5.Text.ToString() + "','" + txtrpn.Text.ToString() + "','" + txtrpm.Text.ToString() + "','" + txtfmn.Text.ToString() + "',,'" + txtfmm.Text.ToString() + "')", con);
                    cmd.ExecuteNonQuery();
                    con.Close();
                    lblsuccess.Text = "Record Inserted Succesfully";
                }
                else
                {
                    lblwarning.Text = "Failed to save the Record";
                }


            }
            catch (Exception ex)
            {
                lblwarning.Text = ex.Message;
            }
        }
        txtfirstName.Text = "";
        txtAddress.Text = "";
        txtpan.Text = "";
        txtaadar.Text = "";
        txtPhone.Text = "";
        txtEmail.Text = "";
        DDLState.Text = "Select State";
        txtdistrict.Text = "";
        txttaluka.Text = "";
        txtvillage.Text = "";
        DropDownList1.SelectedValue = "Select Pin Code";      
        txt1.Text = "";
        txt2.Text = "";
        txt3.Text = "";
        txt4.Text = "";
        txt5.Text = "";
        txtrpn.Text = "";
        txtrpm.Text = "";
        txtfmn.Text = "";
        txtfmm.Text = "";
        

    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownList1.SelectedValue == "")
            {
                txt1.Visible = false;
                txt2.Visible = false;
                txt3.Visible = false;
                txt4.Visible = false;
                txt5.Visible = false;
            }
            else if (DropDownList1.SelectedValue == "1")
            {
                txt1.Visible = true;
                txt2.Visible = false;
                txt3.Visible = false;
                txt4.Visible = false;
                txt5.Visible = false;
            }
            else if (DropDownList1.SelectedValue == "2")
            {
                txt1.Visible = true;
                txt2.Visible = true;
                txt3.Visible = false;
                txt4.Visible = false;
                txt5.Visible = false;
            }
            else if (DropDownList1.SelectedValue == "3")
            {
                txt1.Visible = true;
                txt2.Visible = true;
                txt3.Visible = true;
                txt4.Visible = false;
                txt5.Visible = false;
            }
            else if (DropDownList1.SelectedValue == "4")
            {
                txt1.Visible = true;
                txt2.Visible = true;
                txt3.Visible = true;
                txt4.Visible = true;
                txt5.Visible = false;
            }
            else if (DropDownList1.SelectedValue == "5")
            {
                txt1.Visible = true;
                txt2.Visible = true;
                txt3.Visible = true;
                txt4.Visible = true;
                txt5.Visible = true;
            }
        }
    }






Comments

Popular posts from this blog

How to ReadHtmlFile in string