将动态数组存储到cookie并从aspx.cs页面上的cookie检索另一页面上的动态数组 [英] store dynamic array to cookie and retrive it on another page from cookie on aspx.cs page

查看:71
本文介绍了将动态数组存储到cookie并从aspx.cs页面上的cookie检索另一页面上的动态数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一次在按钮的onclick上存储的值一次.

我在此数组的同一数组中单击另一个值存储.

我想存储在cookie中,当单击按钮时,首先检查cookie数组是否包含任何值(如果是),然后将下一个值添加到同一数组中,否则将其添加到空白数组中.

请帮助尽快解决它的

I have value that store on onclick of button to array once.

I click another value store in same array this array.

I want to store in cookie and when button is click first check if array of cookie contain any value if yes then next value added to same array otherwise it added to blank array .

please help asap its urgent

推荐答案



我认为..

和timberbird一样

因为某些浏览器不允许Cookie.

如果您想像其他颜色一样存储少量数据(例如访问日期)...
您可以按照以下代码检查Cookie是否存在


Hi,

In my view ..

same as timberbird

Because some browsers don''t allow cookies.

If you want to store small amount of data like visited date like some other color...
you can follow this code for checking cookie is existing or not


if (Request.Cookies.Count > 0)
{
    HttpCookieCollection hcc = Request.Cookies;
    string c1 = hcc[0].Value;
    Request.Cookies.Add(new HttpCookie("name", "value"));
}



所以,我的建议是不要开发依赖于cookie的过程

最好的



So,my suggestion is don''t develop process which is depends on cookies

All the Best


将数组存储在cookie中通常不是一个好主意. Cookies可能会被完全清除或禁用,并且它们无论如何都不打算存储潜在的大量数据.考虑改用session或viewstate.
但是,如果确实需要将数组存储在cookie中,则只需在第一页将其序列化为字符串,然后在第二页上反序列化即可.

还有一种可能是我误解了您的问题(考虑到它的晦涩性,这不足为奇),您只需要将两个值放入两个完全不同的 cookie值中-就没有了与动态数组有关.在这种情况下细化问题
It''s generally a bad idea to store arrays in cookies. Cookies may be cleared or disabled completely, and they are not intended to store potentially large volumes of data anyway. Consider using session or viewstate instead.
If, though, you really HAVE TO store array in cookies, just serialize it into string on first page and deserialize on the second.

There''s also a possibility that I misunderstood your question (which would be no surprise, considering how obscure it is) and you just need to put two values in two absolutely different cookie values - which has nothing to do with dynamic arrays. Refine the question in this case


这篇关于将动态数组存储到cookie并从aspx.cs页面上的cookie检索另一页面上的动态数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆