views:

276

answers:

3

ASP .NET is allowed
Storing the values in hidden input fields is allowed
Query String is not allowed
POST request is not allowed

It is possible to store JS variables between GET requests ?
I want to reinitialize them on the client using ClientScript.RegisterStartupScript

Can I use cookies for this ?
Are there other posibilities?
Where cookies are stored when Request is made ?

+2  A: 

Can I use cookies for this ?

Yes, see this tutorial on using cookies in Javascript.

Are there other posibilities?

If you are not allowed to append anything the URL of your requests, I can't come up with any.

Where cookies are stored when Request is made ?

In the HTTP request header. The aforementioned tutorial will tell you how to read their values from Javascript. On the server side with ASP.Net, you can read cookie values using Request.Cookie["cookieName"] which returns an instance of HttpCookie.

Jørn Schou-Rode
A: 

At the moment using cookies is your best bet. You can serialize the JavaScript objects to strings, and unserialize them back into objects later. A good choice format is JSON, since it is a subset of JavaScript.

There is also storing objects in Flash. Storing in Google Gears. DomStorage

See this library that has an interface to each: http://pablotron.org/?cid=1557

If you are in control of all aspects of the page, then you can also wrap the page in a top level frame. Then only refresh the child frame. You can then store content in the parent frame.

You can see this used in sites like GMail, and others where the only thing that changes in the URL is outside the #.

You don't even have to change the URL, that part is just put in for Human Friendly URLs. (So you can actually copy and paste URLs as is).

bucabay
I tried your idea in the past, using Framesets and IFrames. But my site will flicker, all iframes flicker their content, and this result in bad user experience.
pixel3cs
that must have been a while ago. I believe the flickering problem is fixed in most browsers used today. Gmail does not flickr, and it uses Framesets, view the source. There is also workarounds for flickering, but I can't remember exactly what they were since that was a year or two ago.
bucabay
+3  A: 

I wouldn't highly recommend this, but the other option is to alter the window.name property.

You can save some minor bits of data here, then retrieve them on the next page load.

Pros:

  • Quick-n-dirty, but works

Cons:

  • Messes up any window references for popups/child iframes
  • Since its a "hack", browser vendors may break this "feature" in the future

Of course if you can exclude all the old browsers, then use Global/Client Session Storage!

scunliffe