471,089 Members | 1,628 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

Client and Server Side Cookies

I have a page that contains some dhtml and uses client side cookies so store
it's current state so that on clicking the "back" button to it the page will
be as the user last saw it.
However, should the user click on a link to that page, I want to remove the
cookie so that the page is displayed in its default state.
The two ways I can think of doing this is to either have some javascript
code to delete the cookie when the page is first loaded (I do not know how
to do this)
Or, to remove or clear the cookie on the server side Page_Load event which
will only run on a refresh or load of the page.
I am having troubles getting this version to work though.

To write the cookie on the client side, I am using

document.cookie=document.URL + 'State' + '=' + pageState + ';';

The pageState var stores information about how the page should be rendered.
This cookie is read in javascript at the end of the page to reset all the
dhtml to the state in the cookie.

In my Page_Load event on the server side, I have the following code.

Response.Cookies.Add(new HttpCookie(Request.Url.AbsoluteUri+"State", ""));

If anyone can shed any light on why this may not be working that would be
very appreciated. I realise using the Url as the cookie name may not be the
best option but there are no query strings, so the absolute uri and the
document.location are identical.

Many Thanks
Robin
Nov 18 '05 #1
0 1837

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Pål Johansen | last post: by
1 post views Thread by Peter Row | last post: by
reply views Thread by brianpmccullough | last post: by
6 posts views Thread by dinoo | last post: by
13 posts views Thread by Sanders Kaufman | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.