IT Community - Software Programming, Web Development and Technical Support

how to store and retrieve data from cookies

This is a discussion on how to store and retrieve data from cookies within the ASP and ASP.NET Programming forums, part of the Web Development category; //This example shows that how to store and retrieve data from cookies. // Offshore Software Development Company India, Software Development India ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-23-2007, 01:21 AM
hanusoftware hanusoftware is offline
D-Web Trainee
 
Join Date: Jun 2007
Posts: 5
hanusoftware is on a distinguished road
Default how to store and retrieve data from cookies

//This example shows that how to store and retrieve data from cookies.
// Offshore Software Development Company India, Software Development India

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(!IsPostBack)
{
if(Request.Cookies["UserCook"] != null)
{
chkRemember.Checked = true;
HttpCookie cook = Request.Cookies["UserCook"];
txtUserName.Text = cook["UserName"].ToString();

}
}
}
private void btnSubmit_Click(object sender, System.EventArgs e)
{
try
{
if(chkRemember.Checked == true)
{
if(Request.Browser.Cookies == true)
{
HttpCookie loginCook = new HttpCookie("UserCook");
loginCook["UserName"] = txtUserName.Text.Trim();
loginCook.Expires = DateTime.MaxValue;
Response.Cookies.Add(loginCook);
}
else
{
lblErr.Text = "Please enable your cookies in Internet
option in Explorer.";
}
}
if(txtUserName.Text.Trim() == "developer" &&
txtPwd.Text.Trim() == "developer")
{
Session["UserId"] = txtUserName.Text.Trim();
Response.Redirect("Querystring.aspx?Usertype=Web Developer");
}
else if(txtUserName.Text.Trim()=="admin" && txtPwd.Text.Trim()== "admin")
{
Session["UserId"] = txtUserName.Text.Trim();
string str = Server.UrlEncode("Administrator+");

Response.Redirect("Querystring.aspx?UserType="+str );
}
else
{
lblErr.Text = "Invalid user id and password.";
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
}
}

Last edited by Booom : 07-23-2007 at 01:46 AM. Reason: link publicity
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-09-2007, 07:17 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Wink Re: how to store and retrieve data from cookies

Hi,

The above coding is very usefull for me...Here i need to store and retrieve the cookie in asp.net using javascript..
Can u assist me....


Thanks in advance
__________________
H2O

Without us, no one can survive..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Store and retrive flash cookies oxygen Flash Actionscript Programming 4 08-22-2007 11:58 PM
How to Store and Retrieve the values in server side caches in ASP.NET? oxygen ASP and ASP.NET Programming 1 07-23-2007 01:14 AM
How to retrieve SIM card data using j2me? mobilegeek J2ME 0 07-22-2007 10:22 PM
Store and Retrieve the values in cookies in ASP.NET oxygen ASP and ASP.NET Programming 0 07-20-2007 12:23 AM
how to retrieve the data after commit statement vadivelanvaidyanathan Database Support 3 03-21-2007 05:49 AM


All times are GMT -7. The time now is 12:47 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0