473,507 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cookie value doesn't immediately reflect change (vb.net/javascript

JT
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").Va lue.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
Mar 26 '06 #1
0 1815

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5540
by: Michael | last post by:
I am reading and setting a cookie using JavaScript in the BODY onload and onunload events respectively. This works fine. However when I use ASP to set the cookie under some condition where I...
12
17944
by: chrism | last post by:
Hello, I have a pop-up window that I would like to appear in front of the browser home page when a user opens IE. Problem is, I'd like it to never appear again if the user navigates back to the...
3
3615
by: F | last post by:
It seems that document.cookie doesn't work both on Internet Explorer 5 for Mac (OS 9) and Opera 6 for PC... am I doing something wrong? Or does it just not work? I don't get an error message, the...
3
5948
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change...
9
4465
by: Marco Krechting | last post by:
Hi All, I have a page with a list of hyperlinks. I want to save information in a cookie about the fact that I entered an hyperlink or not. When I click one of the hyperlinks I want this stored...
3
11096
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
6
2686
by: kelvlam | last post by:
Hello all, I'm still a bit new with JavaScript, and I hope the guru here can shed some light for me. It's regarding handling cookie and the case-sensitive nature of JavaScript itself. My...
2
6229
by: HopfZ | last post by:
Server sends cookie to browser and the browser send the same cookie back to the server according to Wikipedia. Do browsers send even javascript-generated cookie to servers? For example, if I...
29
2981
by: Jerim79 | last post by:
I did try to find the answer to this before posting, so this isn't a knee jerk reaction. What I am trying to accomplish is to have a script that opens a cookie, reads a value, and then use a...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.