ASP.NET with C# and SQL SERVER , some vb.net . asp.net examples, asp.net codes, asp.net programs, c# code, sql server queries, important codes.
Thursday, 18 October 2012
cookies in asp.net with c#
using System.Collections.Specialized;
protected void bttLogin_Click(object sender, EventArgs e)
{
HttpCookie myCookie = new HttpCookie("yourInfo");
myCookie.Values["yourName"] = txtUsername.Text;
myCookie.Values["yourID"] = txtPassword.Text;
Response.Cookies.Add(myCookie);
}
protected void bttGet_Click(object sender, EventArgs e)
{
HttpCookie getCookie;
getCookie = Request.Cookies["yourInfo"];
if (getCookie.HasKeys)
{
NameValueCollection valueCookie = new NameValueCollection(getCookie.Values);
foreach (string keyTemp in valueCookie.AllKeys)
{
Response.Write(keyTemp + " : ");
Response.Write(getCookie.Values[keyTemp] + "<br />");
}
}
else
{ Response.Write(getCookie.Value); }
lblSum.Text = "Welcome .. " + getCookie.Values["yourName"];
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment