Client and Server Side Cookies

R

Robin Day

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top