Hi guys,
This blog we explain how to write login page
page with remember me check box .
Remember.aspx
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<style type="text/css">
.auto-style1
{
width: 100%;
border-color: #808080;
}
.auto-style2
{
width: 43%;
border-color: #3333CC;
background-color:silver;
}
.auto-style3
{
width: 270px;
}
.auto-style4
{
width: 259px;
}
.auto-style5
{
width: 270px;
height: 35px;
}
.auto-style6
{
height: 35px;
}
</style>
-</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server">
<script src="Scripts/jquery-1.4.1.js"></script>
<script src="Scripts/jquery-1.7.1.min.js"></script>
<script src="Scripts/WaterMark.min.js"></script>
<script src="Scripts/watermark.jquery.js"></script>
<script type="text/javascript">
$(function () {
$("[ID*=txtUserName],[ID*=txtPassWord]").WaterMark();
});
</script>
<table class="auto-style1">
<tr>
<td class="auto-style4">
</td>
<td>
<table class="auto-style2">
<tr>
<td class="auto-style3">
<asp:Label ID="lblName" runat="server" Font-Bold="True" ForeColor="Black" Text="UserName"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtUserName" ToolTip="Enter
username" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style3">
<asp:Label ID="Label3" runat="server" Font-Bold="True" ForeColor="Black" Text="PassWord"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtPassWord" ToolTip="Enter
password" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style5"> </td>
<td class="auto-style6">
<asp:CheckBox ID="chkremember" runat="server" Font-Bold="True" ForeColor="Black" Text="RememberMe" />
</td>
</tr>
<tr>
<td class="auto-style3"> </td>
<td>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/login_2.jpg" Height="26px" OnClick="ImageButton1_Click" Width="65px" />
<asp:Label ID="lblmsg" runat="server" Text="Msg"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style3"> </td>
<td>
<asp:HyperLink ID="HyperLink1" runat="server" Font-Bold="True" ForeColor="Red" NavigateUrl="~/ChangePassword.aspx">Change your password?</asp:HyperLink>
</td>
</tr>
</table>
</td>
<td> </td>
</tr>
</table>
</asp:Content>
Remember.aspx.cs file
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class UserLogin : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["123"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.Cookies["UserName"] != null)
txtUserName.Text =
Request.Cookies["UserName"].Value;
if (Request.Cookies["PassWord"] != null)
txtPassWord.Attributes.Add("value",
Request.Cookies["PassWord"].Value);
if (Request.Cookies["UserName"] != null && Request.Cookies["PassWord"] != null)
chkremember.Checked = true;
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
SqlCommand cmd = new SqlCommand("select UserName ,
PassWord from userregister where UserName ='" + txtUserName.Text + "'
and PassWord ='" + txtPassWord.Text + "'", con);
SqlDataAdapter sdr = new SqlDataAdapter(cmd);
Session["userit"] = txtUserName.Text;
DataSet ds = new DataSet();
sdr.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if (chkremember.Checked == true)
{
Response.Cookies["UserName"].Value
= txtUserName.Text;
Response.Cookies["PassWord"].Value
= txtPassWord.Text;
Response.Cookies["UserName"].Expires
= DateTime.Now.AddDays(15);
Response.Cookies["PassWord"].Expires
= DateTime.Now.AddDays(15);
}
else
{
Response.Cookies["UserName"].Expires
= DateTime.Now.AddDays(-1);
Response.Cookies["PassWord"].Expires
= DateTime.Now.AddDays(-1);
}
Response.Redirect("Mainaccess.aspx");
}
else
{
Response.Write("Invalid username and password");
}
}
}
No comments:
Post a Comment