Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 25, 2012 06:18 PM by barryman9000
Apr 25, 2012 03:34 PM|LINK
How can I Add Multiple values in a Single cookie.
eg: I wish to add All Countries name in a Single Cookie Name "Countries" and read it by using For loop
Thanks in Advance
Apr 25, 2012 03:46 PM|LINK
you can add country names in single string... separated by comma (or other character)
and then add that string value into cookie variable... while reading back, read the string value.. split it by comma and loop through the splitted array.
but remember, cookie size has limitation. a cookie can hold upto 4kb of data only
hope this helps...
Apr 25, 2012 03:57 PM|LINK
This is a very long process.
Is there any other option ?
Apr 25, 2012 04:43 PM|LINK
I'm curious why you'd want to do this? Why store a static list of countries on a client's computer? You could store this as a string in your app and loop through it.
If it has to be a cookie, kedarrkulkarni's soultion of storing a CSV in a cookie would work. It's really not a lengthy process.
Apr 25, 2012 04:50 PM|LINK
Apr 25, 2012 05:28 PM|LINK
you can set cookies like
Response.Cookies["Country"]["1"] = "US";
Response.Cookies["Country"]["2"] = "UK";
and loop through it like
if (Request.Cookies["Country"] != null)
int count= Request.Cookies["Country"].Values.Count;
for (int i = 1; i <=count ; i++)
Apr 25, 2012 06:18 PM|LINK
This is going to create an even bigger headache when the OP tries to update his list (especially if you set each country to some numerical order... unless maybe if you incremented them by 5 or something). And creating this type of multidemensional cookie
array (or whatever it's called) is going to be "a very long process" considering there are almost 200 countries in the world today.
Depending upon the purpose of your app, I'd still look into something like this web service, where you can get a list of all current countries anytime you want: