Database Field
id= int(auot increment and primary key)
username=varchar(50)
password=varchar(50)
//sessionexample.aspx
<div>
<pre>
Email: <asp:TextBox ID="name" runat="server"></asp:TextBox>
password:<asp:TextBox ID="pass" runat="server" TextMode="Password"></asp:TextBox>
<asp:Button ID="btn" runat="server" Text="login"
onclick="btn_Click" />
</pre>
</div>
C# code for sessionexample.aspx
protected void btn_Click(object sender, EventArgs e)
{
SqlDataAdapter dap = new SqlDataAdapter("select * from login where username='"+name.Text+"' and password='"+pass.Text+"'",con);
DataSet ds = new DataSet();
dap.Fill(ds);
Session["username"] = ds.Tables[0].Rows[0][1].ToString();
Response.Redirect("sessionexample2.aspx");
}
now we get the session ,create new page sessionexample2.aspx
<head>
<style type="text/css">a {text-decoration: none}</style>
</head>
<div>
<asp:Label ID="lb" runat="server" ForeColor="#6699FF" ></asp:Label> <a href="sessionexample.aspx" style="text-decoration: none; ">logout</a>
</div>
C# code for sessionexample2.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack != true)
{
lb.Text = Session["username"].ToString();
}
}
No comments:
Post a Comment