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...
Cheers!
KK
Please mark as Answer if post helps in resolving your issue
My Site
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.
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.
sels2005j
Member
175 Points
180 Posts
Multiple Values in a Single Cookie in ASP.net C#
Apr 25, 2012 03:34 PM|LINK
Hi Friends,
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
Please Help
Thanks in Advance
kedarrkulkar...
All-Star
34013 Points
5468 Posts
Re: Multiple Values in a Single Cookie in ASP.net C#
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...
KK
Please mark as Answer if post helps in resolving your issue
My Site
sels2005j
Member
175 Points
180 Posts
Re: Multiple Values in a Single Cookie in ASP.net C#
Apr 25, 2012 03:57 PM|LINK
This is a very long process.
Is there any other option ?
barryman9000
Participant
1698 Points
605 Posts
Re: Multiple Values in a Single Cookie in ASP.net C#
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.
http://msdn.microsoft.com/en-us/library/78c837bd(v=vs.85).aspx
- George Carlin
sriramabi
Contributor
4351 Points
1277 Posts
Re: Multiple Values in a Single Cookie in ASP.net C#
Apr 25, 2012 04:50 PM|LINK
Hai
http://www.c-sharpcorner.com/Blogs/8809/get-and-set-multiple-values-in-a-single-cookie-in-Asp-Net.aspx
thank u
sagarbandal
Member
56 Points
10 Posts
Re: Multiple Values in a Single Cookie in ASP.net C#
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++)
{
Response.Write(Request.Cookies["Country"][i.ToString()].ToString());
}
}
barryman9000
Participant
1698 Points
605 Posts
Re: Multiple Values in a Single Cookie in ASP.net C#
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:
http://www.webservicex.net/country.asmx?op=GetCountries
- George Carlin