I have an aspx page (page1.aspx) with this:
<body onload="SetCookies();">
<script>
function SetCookies() {
document.cookie = "year=2012";
document.cookie = "model=Impala";
}
</script>
Then in the page1.aspx.vb I have this:
Response.Cookies("year").Value = ""
Response.Cookies("model").Value = ""
ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "redirect", "window.parent.location='page2.aspx'", True)
Finally in page2.aspx I have:
<body onload="ShowCookies();">
<script>
function ShowCookies() {
var mycookies = document.cookie.split(';');
var aString = '';
for (var i = 1; i <= mycookies.length; i++)
aString += i + ' ' + mycookies[i - 1] + "\n";
console.log(aString);
}
</script>
The problem is that I am getting this in console:
1 year=2012
2 model=Impala
3 year=
4 model=
Instead to update my existing cookies it is creating new cookies with the same name. What am I doing wrong?