Hi ,
This Example will Guide you .
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie CookieName = Request.Cookies["username"];
if (!IsPostBack)
{
if (CookieName != null)
{
LoginDiv.Visible = false;
Label3.Visible = true;
Label3.Text = CookieName.Value;
Button2.Visible = true;
}
else
{
LoginDiv.Visible = true;
Label3.Visible = false;
Button2.Visible = false;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (CheckBox1.Checked ==true)
{
HttpCookie CookieName = new HttpCookie("username");
CookieName.Value = TextBox1.Text;
CookieName.Expires = DateTime.Now.AddDays(90);
Response.Cookies.Add(CookieName);
LoginDiv.Visible = false;
Label3.Visible = true;
Button2.Visible = true;
Label3.Text = CookieName.Value;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
HttpCookie CookieName = Request.Cookies["username"];
CookieName.Expires.AddMilliseconds(1);
CookieName.Value = null;
Response.Cookies.Add(CookieName);
LoginDiv.Visible = true;
Label3.Visible = false;
Button2.Visible = false;
}
<div id="LoginDiv" runat="server">
<asp:Label ID="Label1" runat="server" Text="user name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:CheckBox ID="CheckBox1" runat="server" Text="Remember me" />
<br />
<asp:Button ID="Button1" runat="server" Text="Login" onclick="Button1_Click" />
</div>
<div>
<asp:Label ID="Label3" runat="server" Text="Label" Visible="False"></asp:Label>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="log out" />
</div>
Best Regards
M.Mitwalli