G
Guest
I posted a question earlier about communicating between a javascript function
and vb.net. In the end I decided to try using a cookie. I use the
following javascript function (from vb.net) to set the cookie:
sb.Append("<script language='javascript'>")
sb.Append("{if (confirm('Are you sure? ') == true)")
sb.Append("{var date = new Date();
date.setTime(date.getTime()+(60*60*1000)); var expires = '
expires='+date.toGMTString(); document.cookie = 'confirmcookie=1;' + expires
+ '; path=/'}")
sb.Append("else {var date = new Date();
date.setTime(date.getTime()+(60*60*1000)); var expires = '
expires='+date.toGMTString(); document.cookie = 'confirmcookie=0;' + expires
+ '; path=/'}}")
sb.Append("</script>")
Response.Write(sb.ToString())
Response.Flush()
I then try to access that value with the following code:
If Not Request.Cookies("confirmcookie") Is Nothing Then
Response.Write(Request.Cookies("confirmcookie").Value.ToString)
end if
Here's the deal. These two snippets of code are inside a server-side event
of mine. The first time they are called, the cookie appears to be set, but
the value isn't there. The second time they are called, I think the cookie
is still being set, but the value that shows up is from the last time
the cookie was set. It continues on that way, every time returning the value
from the previous time the cookie was set and not the most recent. I even
tried to somehow delete the cookie so that wouldn't happen, but it didn't
work. I tried both a javascript based version:
Response.Write("<script language='javascript'>var expires = ' expires=Thu,
01-Jan-70 00:00:01 GMT; document.cookie = 'confirmcookie=null;' + expires +
'; path=/'</script>")
Response.Flush()
and vb.net version:
Response.Cookies("confirmcookie").Value = ""
Response.Cookies("confirmcookie").Expires = DateTime.Now.AddYears(-50)
but neither helped.
Does anyone have any idea what I'm doing wrong?
Thanks for the help,
JT
and vb.net. In the end I decided to try using a cookie. I use the
following javascript function (from vb.net) to set the cookie:
sb.Append("<script language='javascript'>")
sb.Append("{if (confirm('Are you sure? ') == true)")
sb.Append("{var date = new Date();
date.setTime(date.getTime()+(60*60*1000)); var expires = '
expires='+date.toGMTString(); document.cookie = 'confirmcookie=1;' + expires
+ '; path=/'}")
sb.Append("else {var date = new Date();
date.setTime(date.getTime()+(60*60*1000)); var expires = '
expires='+date.toGMTString(); document.cookie = 'confirmcookie=0;' + expires
+ '; path=/'}}")
sb.Append("</script>")
Response.Write(sb.ToString())
Response.Flush()
I then try to access that value with the following code:
If Not Request.Cookies("confirmcookie") Is Nothing Then
Response.Write(Request.Cookies("confirmcookie").Value.ToString)
end if
Here's the deal. These two snippets of code are inside a server-side event
of mine. The first time they are called, the cookie appears to be set, but
the value isn't there. The second time they are called, I think the cookie
is still being set, but the value that shows up is from the last time
the cookie was set. It continues on that way, every time returning the value
from the previous time the cookie was set and not the most recent. I even
tried to somehow delete the cookie so that wouldn't happen, but it didn't
work. I tried both a javascript based version:
Response.Write("<script language='javascript'>var expires = ' expires=Thu,
01-Jan-70 00:00:01 GMT; document.cookie = 'confirmcookie=null;' + expires +
'; path=/'</script>")
Response.Flush()
and vb.net version:
Response.Cookies("confirmcookie").Value = ""
Response.Cookies("confirmcookie").Expires = DateTime.Now.AddYears(-50)
but neither helped.
Does anyone have any idea what I'm doing wrong?
Thanks for the help,
JT