Click here to Skip to main content
11,438,752 members (76,322 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Dear Sir/Ma'am

I am using asp.net with VB as default language and using sql server as backend .
I want to store multiple values in a Single Cookie .
Please Help me regarding this.

Sir i have a form

id (textbox1)

(Button 1)


Sir I want that i put the id as 1 in textbox1 and click on button then value of text box add in the cookie.

At this time in the cookie we have value
1


And when again i put the id as 2 in text box1 and click on the button then 2 also add in the cookie.

Now When i see the value of cookie then it must shows the values as
1
2

Please Help me to do this task
Posted 14-Feb-13 18:00pm
ankur7891.4K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,

Use of cookies:

////////////SET THE COOKIE//////////////

Response.Cookies["test"].Value = UserName.Text ;
 
Response.Cookies["test"].Expires = DateTime.Now.AddYears(30);
 
where test is the cookie name
 
and the username.text is the textbox that will be used to define the cookies information
 
in order to delete a cookie use this
Response.Cookies["test"].Expires = DateTime.Now.AddYears(-30);
 
in order to check whether the cookie is found or not and retrieve the cookies information use this
/////////check to see if cookie presented//////////

if (Request.Cookies["test"] == null)
 
TextBox2.Text = "No cookie found";
 
else
 
TextBox2 .Text = Request.Cookies["test"].Value;
 
/////////END check to see if cookie presented//////////

For multiple values refer the following links:

Storing multiple values in cookies
ASP.NET cookies with multiple values - how to?

Hope this will hep you.
Thanks
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Basics of Cookies in ASP.NET[^] should help you get started with the basics.
How to: Write a Cookie[^] is another good basic link.

Beginner's Guide to ASP.NET Cookies[^] could be useful too.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.150506.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100