Is it impossible to modify the value of a cookie that has been established in JavaScript

I have an <asp:CheckBox OnClick=""> linked to a JavaScript function that sets a cookie value like this:

document.cookie = "cv0_value=1";

In my .Net code-behind, I am retrieving the cookie value using the following code, and everything seems to be functioning correctly.

cv0_value = Request.Cookies["cv0_value"].Value == "0" ? false : true;

The problem arises when I try to update the cookie value in the .Net code-behind - it does not seem to change the actual cookie value.

HttpContext.Current.Request.Cookies["cv0_value"].Value = "0";

Upon checking the cookie value again in the code-behind, I notice that it remains set to the original value assigned by the JavaScript.

Even after multiple calls to the Page_Load method and reviewing the Request and Response, the updated value is not reflected in the cookie. Despite setting the Response with the new value, on subsequent Page_Load calls, the Request still contains the initial value.

Although I initially thought the issue might be related to referencing from a static method, further exploration revealed that the use of HttpContext.Current.Response does not seem to be causing the problem in my specific case as detailed here. Can anyone shed light on what could be happening?

Answer №1

Once the value is set, remember to save it.

HttpCookie cookie = HttpContext.Current.Request.Cookies["cv0_value"];
if (cookie != null)
{
   cookie.Value ="0";
   HttpContext.Current.Response.Cookies.Add(cookie);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unraveling based on changing values in es6

Trying to retrieve query parameters from the frontend in my express endpoint. const { filterType1, filterType2 } = req.query However, the issue is that the filterType values are coming from a predefined list of array elements. const list = ['priceF ...

There is no exception occurrence for MongDB

Currently, I am utilizing MongoDB driver version 2.7.3. I have been researching MongoExceptions and seeking information about them. Below is an excerpt from my code: public IList<Evaluation> GetReviews() { try { ...

What is the best way to handle requests once a SpookyJS script has finished running?

Occasionally, I find myself needing to log in and extract some data from a specific website. To automate this process, I developed a CasperJS script that runs on Heroku. My goal is to create an endpoint like the following: app.get('/test', func ...

Present the contents of directories and files stored on a remote desktop computer through a website interface

I've been working on creating a website that can display the folders and files from a remote computer. I've explored options like RDP and RDC, but they require a remote desktop application to access. Currently, I am using asp.net, C#, and JavaScr ...

Methodically substitute namespaces

My team has been working on a large C#/ASP.NET application that we now need to repurpose for other projects. I'm looking to update our project-specific namespaces to make them more generic. I've tried using the right-click refactor on the namesp ...

Tips for converting this ajax code to long polling

I am currently using this ajax code and I was wondering if anyone knows how to change it to long polling. Here is the code I am using: var chat = {} chat.fetchMessages = function () { $.ajax({ url: 'ajax/ajax/chat.php', type: 'PO ...

What could be causing Wordpress Jquery to only function properly after a page refresh?

Here is the code snippet I am working with: <script type="text/javascript"> jQuery( document ).ready(function() { jQuery('#bookbtn_loc_1').on('click', function(event){ jQuery("a.da-close").click(); ...

What strategies can be used to prevent a "flashing" progress div when receiving rapid results using jQuery ajax?

Currently, I am utilizing jQuery to make AJAX calls to an ASP.NET backend using a specific method. Within this process, I am implementing .ajaxStart and .ajaxStop to display and hide a progress indicator. However, when the AJAX request completes rapidly, t ...

What is causing the issue with dynamic special characters not functioning properly in my React router?

I am working with 3 components named App.js, SearchCategoryPage.js, and Home.js. However, when I click on the search icon, it does not navigate me to the search page. What could be the reason for this issue? App.js const outlet_id = useSelector((state) =& ...

How can I transfer an array of objects obtained from an ajax call to an observable array?

One of my functions involves making an ajax call and receiving data in the callback. It looks something like this: function fetchData(callback) { //perform ajax if(callback) { callback(data.data); } } If I use the function like this: fetc ...

Is there a way to automatically display the detailsPanel in Material-table upon loading?

I am currently working on creating a subtable for the main React Material-Table. So far, everything is functioning correctly as expected, with the details panel (subtable) appearing when the toggle icon is pressed. Is there a way to have it displayed by d ...

Step-by-step guide for properly transferring PHP MySQL data to ChartJs

I am looking to create bar charts and pie charts using ChartJs, with data fetched from php and mysql. Specifically, I want to generate a bar chart that illustrates the statistics of male and female students, along with the total number of students. The des ...

Implementing a JavaScript Date object within a Kendo Grid

As a newcomer to web development, I recently came across an issue while testing some basic functionalities. In my database, I have data stored in SQL datetime format in UTC GTC timezone: Link to Database To display this data in a Kendo Grid and append "U ...

A series of Ajax requests looping through jQuery functionality

I'm seeking advice on a coding dilemma I have. Currently, I am attempting to retrieve JSON Data through AJAX using jQuery. My challenge lies in the fact that I require more data than can be obtained in just 1 or 2 Ajax calls. Therefore, I am lookin ...

Angular alert: The configuration object used to initialize Webpack does not conform to the API schema

Recently encountered an error with angular 7 that started popping up today. Unsure of what's causing it. Attempted to update, remove, and reinstall all packages but still unable to resolve the issue. Error: Invalid configuration object. Webpack ini ...

Tips for retrieving values from CheckBox in Asp.net MVC using Jquery

I'm currently facing a dilemma while working on an MVC web application. I have dynamically generated checkboxes from my database, but I am uncertain about how to extract the value of the selected checkbox and store it in the database. Any suggestions? ...

Enabling Cross-Origin Resource Sharing in Node.js 14

I'm diving into the world of JavaScript and Node.js as I work on creating a new REST-based API using NodeJS. However, I've hit a roadblock when trying to fetch data from the API due to a CORS issue. Browser console error message: Access to fetch ...

The request to sign up at http://localhost:3000/api/signup resulted in a 400 (Bad Request

Having recently started working with the MEAN stack, I've run into some issues when trying to send registration data using http.post. Below is my server code: var express = require('express'), bodyParser = require('body-parser' ...

I am puzzled as to why my Details Modal keeps appearing whenever I click anywhere, even when I have specifically added it to only show up on the event of today. Additionally, I am encountering

ERROR Function components cannot have string refs. We recommend using useRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref at coerceRef (http://localhost:3000/static/js/bundle.js:59386:21) at createChil ...

Using jQuery to make a call to a VB.NET function and then using the response to fill in the content

I have implemented the following code: $("#dropdownPaper").change(function () { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "NomexLine500A.aspx/Ca ...