</connectionStrings>
Monday, 26 December 2011
How to create Login Page in Asp.net with Connected Mode
How to create Login Page in Asp.net with Connected Mode……………………………
// create database test………………………
Create database test
Use test
// create table LoginTable in database test………………………
create table LoginTable ( EmailId nvarchar(50) primary key,Password nvarchar(50),LoginTime nvarchar(50),Role nvarchar(50),Status nvarchar(50) ,SQues nvarchar(50),SAns nvarchar(50))
<%@ Page Title="Login Page"
Language="C#"
MasterPageFile="~/Main.master"
AutoEventWireup="true"
CodeFile="Login.aspx.cs"
Inherits="Login"
%>
<asp:Content ID="Content1"
ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<table style="width: 100%">
<tr>
<td>
</td>
<td colspan="2">
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Font-Bold="True" Text="EmailId"></asp:Label>
</td>
<td colspan="2">
<asp:TextBox ID="txtemailid" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtemailid" ErrorMessage="Please enter emailid"
SetFocusOnError="True" ValidationGroup="g1" ForeColor="Red">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtemailid" ErrorMessage="not valid format"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup="g1" ForeColor="Red">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" runat="server" Font-Bold="True" Text="Password"></asp:Label>
</td>
<td colspan="2">
<asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtpassword" ErrorMessage="Please enter password"
ValidationGroup="g1" ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td style="height: 27px">
</td>
<td style="height: 27px">
<asp:Button ID="Button2" runat="server" Height="25px" onclick="Button1_Click"
Text="Login" ValidationGroup="g1" />
</td>
<td style="height: 27px">
<asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="~/Regitration.aspx">Sign Up</asp:HyperLink>
</td>
</tr>
<tr>
<td colspan="3" style="height: 27px">
<center>
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Forget Password</asp:LinkButton>
</center>
</td>
</tr>
<tr>
<td colspan="3" style="height: 27px" align="center">
<asp:Label ID="Label17" runat="server" Visible="False" ForeColor="Red"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td colspan="2">
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
ForeColor="Red"
/>
</td>
</tr>
</table>
</asp:Content>
// this code for
web configuration file …………………
<configuration>
<connectionStrings>
<add name="kush" connectionString="Data Source=KUSH-PC\KUSH;Initial
Catalog=SocialNet;Integrated Security=True"/>
</connectionStrings>
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.Configuration;
using System.IO;
using System.Web.Security;
public partial class Login :
System.Web.UI.Page
{
SqlConnection
con;
SqlCommand
cmd;
SqlDataReader
dr;
protected void Page_Load(object
sender, EventArgs e)
{
con = new
SqlConnection(ConfigurationManager.ConnectionStrings["kush"].ConnectionString);
}
protected void Button1_Click(object
sender, EventArgs e)
{
try
{
cmd = new
SqlCommand("select
EmailId,Password,Status from LoginTable where EmailId=@EmailId and Password=
@Password", con);
cmd.Parameters.AddWithValue("@EmailId", txtemailid.Text);
cmd.Parameters.AddWithValue("@Password", txtpassword.Text);
con.Open();
dr = cmd.ExecuteReader();
if
(dr.Read())
{
if
(dr["Status"].ToString() == "True")
{
Session["email"] = dr["EmailId"];
FormsAuthentication.RedirectFromLoginPage("a", false);
Response.Redirect("UserHome.aspx");
}
else
{
Label17.Visible = true;
Label17.Text = "Your Account is not active";
}
}
else
{
Label17.Visible = true;
Label17.Text = "EmailId and
Password is not match Please try
again...........";
}
}
catch (Exception ex)
{
Label17.Visible = true;
Label17.Text = ex.Message;
}
}
protected void LinkButton1_Click(object
sender, EventArgs e)
{
Session["email"]
= txtemailid.Text;
Response.Redirect("ForgetPassword.aspx");
}
}
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">
</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;
}
}
}
