Share Blog

Wednesday, September 09, 2015

How To create Registration Form in Asp.net



--------------------------------Create a Table ------------------------------------------------------------

CREATE TABLE Employee
(
      [Empid] [int] IDENTITY(1,1) Primary Key NOT NULL,
      [Fname] [nvarchar](50) NULL,
      [Lname] [nvarchar](50) NULL,
      [Password] [nvarchar](50) NULL,
      [Email] [nvarchar](50) NULL,
      [Address] [nvarchar](150) NULL
     
)

Once we finish TABLE creation in database now open your aspx page and write the code like as shown belowAfter completion of aspx page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Registration.aspx.cs" Inherits="Registration" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How To Create Registration Page in Asp.net</title>
    <style type="text/css">
    #div {
        width:450px;
        margin:0 auto;
        font-family:Verdana, sans-serif;
    }
    legend {
        color:#0481b1;
        font-size:16px;
        padding:0 10px;
        background:#fff;
        -moz-border-radius:4px;
        box-shadow: 0 1px 5px rgba(4, 129, 177, 0.5);
        padding:5px 10px;
        text-transform:uppercase;
        font-family:Helvetica, sans-serif;
        font-weight:bold;
    }
    fieldset {
        border-radius:4px;
        background: #fff;
        background: -moz-linear-gradient(#fff, #f9fdff);
        background: -o-linear-gradient(#fff, #f9fdff);
        background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#f9fdff)); /
        background: -webkit-linear-gradient(#fff, #f9fdff);
        padding:20px;
        border-color:rgba(4, 129, 177, 0.4);
    }
    input,
    textarea {
        color: #373737;
        background: #fff;
        border: 1px solid #CCCCCC;
        color: #aaa;
        font-size: 14px;
        line-height: 1.2em;
        margin-bottom:15px;

        -moz-border-radius:4px;
        -webkit-border-radius:4px;
        border-radius:4px;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) inset, 0 1px 0 rgba(255, 255, 255, 0.2);
    }
    input[type="text"],
    input[type="password"]{
        padding: 8px 6px;
        height: 22px;
        width:280px;
    }
    input[type="text"]:focus,
    input[type="password"]:focus {
        background:#f5fcfe;
        text-indent: 0;
        z-index: 1;
        color: #373737;
        -webkit-transition-duration: 400ms;
        -webkit-transition-property: width, background;
        -webkit-transition-timing-function: ease;
        -moz-transition-duration: 400ms;
        -moz-transition-property: width, background;
        -moz-transition-timing-function: ease;
        -o-transition-duration: 400ms;
        -o-transition-property: width, background;
        -o-transition-timing-function: ease;
        width: 380px;
       
        border-color:#ccc;
        box-shadow:0 0 5px rgba(4, 129, 177, 0.5);
        opacity:0.6;
    }
    input[type="submit"]{
        background: #222;
        border: none;
        text-shadow: 0 -1px 0 rgba(0,0,0,0.3);
        text-transform:uppercase;
        color: #eee;
        cursor: pointer;
        font-size: 15px;
        margin: 5px 0;
        padding: 5px 22px;
        -moz-border-radius: 4px;
        border-radius: 4px;
        -webkit-border-radius:4px;
        -webkit-box-shadow: 0px 1px 2px rgba(0,0,0,0.3);
        -moz-box-shadow: 0px 1px 2px rgba(0,0,0,0.3);
        box-shadow: 0px 1px 2px rgba(0,0,0,0.3);
    }
    textarea {
        padding:3px;
        width:96%;
        height:100px;
    }
    textarea:focus {
        background:#ebf8fd;
        text-indent: 0;
        z-index: 1;
        color: #373737;
        opacity:0.6;
        box-shadow:0 0 5px rgba(4, 129, 177, 0.5);
        border-color:#ccc;
    }
    .small {
        line-height:14px;
        font-size:12px;
        color:#999898;
        margin-bottom:3px;
    }
</style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="div">
        <form action="" method="post">
            <fieldset>
                <legend>Register Form</legend>
                <div>
                    <asp:TextBox ID="txtfirstname" runat="server" placeholder="First Name"></asp:TextBox>
                   
                </div>
                <div>
                    <asp:TextBox ID="txtlastname" runat="server" placeholder="Last Name"></asp:TextBox>
                  
                </div>
                <div>
                    <asp:TextBox ID="txtpassword" runat="server" placeholder="Password" TextMode="Password"></asp:TextBox>
                 
                </div>
                <div>
                    <asp:TextBox ID="txtemail" runat="server" placeholder="Email"></asp:TextBox>
                   
                </div>
                <div>
                    <asp:TextBox ID="txtaddress" runat="server" placeholder="Address" TextMode="MultiLine"></asp:TextBox>
                   
                </div>
                <asp:Button ID="Btnsubmit" runat="server" Text="Submit"
                    onclick="Btnsubmit_Click"  />
               
            </fieldset>   
        </form>
    </div>
    </form>
</body>
</html>

Add following namespaces in codebehind

using System.Data.SqlClient;
using System.Data;

After completion of adding namespaces you need to write the code like as shown below

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


public partial class Registration : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=LENOVO-PC;Initial Catalog=Sunil;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Btnsubmit_Click(object sender, EventArgs e)
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("Insert into Employee values(@Fname,@Lname,@Password,@Email,@Address)",con);
        cmd.Parameters.AddWithValue("@Fname",txtfirstname.Text);
        cmd.Parameters.AddWithValue("@Lname", txtlastname.Text);
        cmd.Parameters.AddWithValue("@Password", txtpassword.Text);
        cmd.Parameters.AddWithValue("@Email", txtemail.Text);
        cmd.Parameters.AddWithValue("@Address", txtaddress.Text);
        cmd.ExecuteNonQuery();
        Response.Write("<script>alert('Registration Successful');</script>");
        con.Close();
    }
}



No comments:

Post a Comment