0

How to store every page textbox value into a cookies. I have 10 asp.net webforms and more. I want store my every page textbox data in a cookies. Dont delete previous page textbox value, it will add it, I want to access as individual textbox data.

Please Help me........ Thank you...

Dan Bracuk
  • 20,699
  • 4
  • 26
  • 43
NagaRaju
  • 5
  • 1
  • 5

2 Answers2

3

The cookies have limits, and they moved forth and back on each element you call on the page, even if its image.

This is not an answer to say "Don't do this", its an answer that I say, you can not do this. You CAN NOT save large amount of data on the cookies due to cookies limitations that are different on each browser.

Use some database to save and retrieve your data. If you continue with trying to save large text on the cookies, your clients will end up with blank pages and no one know where this bug come from.

On this page there is a tool to test the cookie limits: http://browsercookielimits.x64.me/

From the above page:

Typically, the following are allowed:  
300 cookies in total  
4096 bytes per cookie   
20 cookies per domain  
81920 bytes per domain   

Reference: What are the current cookie limits in modern browsers?

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150
1

You can use cookies to store each page textbox values. For example,

HttpCookie cookie = new HttpCookie("myCookie");
cookie.Values.Add("textbox1", txtBox1.Text);
cookie.Values.Add("textbox2", txtBox2.Text);

//get the values out
string name = response.Cookies["myCookie"]["textbox1"];
string address = response.Cookies["myCookie"]["textbox2"];

Also, refer to ASP.NET Cookies Overview.

  • your example will overwrite previous´ page values if the textbox id's are equal. You need to add a kind of page identification to the keys. However, Aristos answer supersedes the cookie solution anyway. – Schadensbegrenzer May 29 '14 at 09:35