Link to home
Start Free TrialLog in
Avatar of rwallacej
rwallacej

asked on

ASP.net modify cookie created in javascript

Hi

I am using a cookie in javascript like this.....answer to previous question.
            var intX = 123;
            document.cookie = "xPos=!~" + intX + "~!";
on a page say Page1.aspx so that postbacks on same page remember value

However when clicking a button on e.g. Page2.aspx which links to Page1.aspx I want to delete the cookie before going to Page1.aspx (so it isn't there anymore and a check to
if(strCook.indexOf("!~")!=0)
is false,
instead of true as it is after doing document.cookie = "xPos=!~" + intX + "~!";

Never used cookies before so this is all new.

Thanks in advance for help.
ASKER CERTIFIED SOLUTION
Avatar of VoteyDisciple
VoteyDisciple

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rwallacej
rwallacej

ASKER

Hi,

Thanks for link/code.
I tried this in advance of posting question.
Response.Cookies("xPos").Expires = DateTime.Now.AddYears(-30)

Now I tried
Dim c As System.Web.HttpCookie = Response.Cookies("xPos")
to check existing but the value of it is blank and data #12:00:00 AM#

Despite setting
Response.Cookies("xPos").Expires = DateTime.Now.AddYears(-30)

the Page1.aspx still thinks it is there, and has value it had as if it wasn't deleted

So something isn't working right still - cookie still exists on page loading up
if i understand your problem correctly you want to delete the cookie when the page loads because as the page is loading for the first time the xposition is not there

if i am correct then in you page load you can add the following code

if (IsPostBack == false)
     Response.Cookies.Remove("Cookie Name");

and you are setting the cookie from your javascript code
ragi0017,

you are correct.
the first time the page is loaded, I do not want xPos to be there; I do not want to remember xPos from previous visits to this page, only during postbacks

the cookie is set in javascript when user uses a scrollbar to remember the X position of scrollbar after postback.

I have found that even with
if (IsPostBack == false)
     Response.Cookies.Remove("Cookie Name");

set, xPos is still remembered.

I also tried
Response.Cookies("xPos").Value = 0
to set the value to zero but it still retains the value set in javascript / the value isn't deleted (so the horizontal navigator always scrolls to xPos)

not sure what's happening
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
cheers for help