Monday, 26 December 2011

How to create Registration Page in Asp.Net



How to create Registration Page  in Asp.Net with ConnectedMode………………………….

// execute query in sql server for create database and Registration table

create database test
use test
create table Registration (Name nvarchar(50),Gender nvarchar(50),Qulification nvarchar(50),EmailId nvarchar(50) primary key,Password nvarchar(50),CurrentCity nvarchar(50),SQues nvarchar(max),SAns nvarchar(50))

// code for Registration.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></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            height: 25px;
        }
        .style3
        {
            width: 272px;
        }
      
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <table class="style1">
            <tr>
                <td class="style2" colspan="2">
                    <marquee>My First Regitration Page</marquee></td>
            </tr>
            <tr>
                <td class="style3">
                    <asp:Label ID="Label3" runat="server"  Text="Name"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style3">
                    <asp:Label ID="Lgender" runat="server" Text="Gender"></asp:Label>
                </td>
                <td>
                    <asp:RadioButtonList ID="rbgender" runat="server" RepeatDirection="Horizontal">
                        <asp:ListItem Selected="True">Male</asp:ListItem>
                        <asp:ListItem>Female</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td class="style3">
                    <asp:Label ID="Lqualification" runat="server" Text="Qualification"></asp:Label>
                </td>
                <td>
                    <asp:DropDownList ID="ddlqual" runat="server">
                        <asp:ListItem Selected="True">----Select----</asp:ListItem>
                        <asp:ListItem>BBA</asp:ListItem>
                        <asp:ListItem>MBA</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td class="style3">
                    <asp:Label ID="Lemail" runat="server" Text="Email"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style3">
                    <asp:Label ID="Lpassword" runat="server" Text="Password"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style3">
                    <asp:Label ID="Lconfirmpassword" runat="server" Text="Confirm Password"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtcpassword" runat="server" TextMode="Password"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style3">
                    <asp:Label ID="Label9" runat="server" Text="Current City"></asp:Label>
                </td>
                <td>
                    <asp:DropDownList ID="ddlcurrentcity" runat="server">
                        <asp:ListItem Selected="True">----Select----</asp:ListItem>
                        <asp:ListItem>New Delhi </asp:ListItem>
                        <asp:ListItem>Mumbai</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td class="style3">
                    <asp:Label ID="Label10" runat="server" Text="Security Quetion"></asp:Label>
                </td>
                <td>
                    <asp:DropDownList ID="ddlsquestion" runat="server">
                        <asp:ListItem Selected="True">----Select----</asp:ListItem>
                        <asp:ListItem>What is your father middle name ?</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td class="style3">
                    <asp:Label ID="Label11" runat="server" Text="Security Answer"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtans" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style3">
                    &nbsp;</td>
                <td>
                    <asp:Button ID="btnregistration" runat="server" onclick="btnregistration_Click"
                        Text="Registration" />
                    <asp:Label ID="lblmessage" runat="server" Visible="False"></asp:Label>
                </td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>

// code for Registration.aspx.cs page…………………………………………………………


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.Drawing;

public partial class Registration : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
   
    protected void btnregistration_Click(object sender, EventArgs e)
    {
        try
        {
            SqlConnection con = new SqlConnection("Data Source=KUSH-PC\\KUSH;Initial Catalog=test;Integrated Security=True");
       
  // SqlCommand cmd = new SqlCommand("insert into Registration  values('" + txtname.Text + "','" + rbgender.SelectedValue + "','" + ddlqual.SelectedValue + "','" + txtemail.Text + "','" + txtpassword.Text + "','" + ddlcurrentcity.SelectedItem.Text + "','" + ddlsquestion.SelectedItem.Text + "','" + txtans.Text + "')", con);

//or
            SqlCommand cmd = new SqlCommand("insert into Registration  values(@name,@Gender,@Qulification,@EmailId,@Password,@CurrentCity,@SQues,@SAns)", con);
            cmd.Parameters.AddWithValue("@name", txtname.Text);
            cmd.Parameters.AddWithValue("@Gender", rbgender.SelectedValue);
            cmd.Parameters.AddWithValue("@Qulification", ddlqual.SelectedItem.Text);
            cmd.Parameters.AddWithValue("@EmailId", txtemail.Text);
            cmd.Parameters.AddWithValue("@Password", txtpassword.Text);
            cmd.Parameters.AddWithValue("@CurrentCity", ddlcurrentcity.SelectedValue);
            cmd.Parameters.AddWithValue("@SQues", ddlsquestion.SelectedValue);
            cmd.Parameters.AddWithValue("@SAns", txtans.Text);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            lblmessage.Visible = true;
            lblmessage.ForeColor = Color.Green;
            lblmessage.Text = "Regitration Successfully";
        }
        catch (Exception EX)
        {
            lblmessage.Visible = true;
            lblmessage.ForeColor = Color.Red;
            lblmessage.Text = EX.Message;
        }
       
    }
}
registration.png

2 comments:

  1. Thanks 4 sharing the post of create the registration page on asp.net
    asp.net training in jaipur

    ReplyDelete
  2. Thanks 4 sharing the post of create the registration page on asp.net
    asp.net training in jaipur

    ReplyDelete