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.
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("!~")!=
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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("C ookie Name");
and you are setting the cookie from your javascript code
if i am correct then in you page load you can add the following code
if (IsPostBack == false)
Response.Cookies.Remove("C
and you are setting the cookie from your javascript code
ASKER
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("C ookie Name");
set, xPos is still remembered.
I also tried
Response.Cookies("xPos").V alue = 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
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("C
set, xPos is still remembered.
I also tried
Response.Cookies("xPos").V
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
cheers for help
ASKER
Thanks for link/code.
I tried this in advance of posting question.
Response.Cookies("xPos").E
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").E
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