Exploring the world of session cookies in ASP.NET using C#

Can someone please assist me? I am trying to pass information from page 1 to page 2 using cookies. However, every time I click the "add" button, a new cookie is set instead of modifying the value and keeping the same name. How can I read all cookies as a list?

Here is my code:

 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />


        protected void Button1_Click(object sender, EventArgs e)
        {
            HttpCookie Cookie = new HttpCookie("result");            

            Cookie["text1"] = TextBox1.Text;
            Cookie["text2"] = TextBox2.Text;
            Cookie.Expires = DateTime.Now.AddDays(2);
            Response.Cookies.Add(Cookie);
           Response.Redirect("WebForm2.aspx");


        }



        protected void Page_Load(object sender, EventArgs e)
        {

            HttpCookie Cookie = Request.Cookies["result"];
            if (Cookie != null)
            {

                Ldonate.Text = Cookie["text1"] ;
                Litem.Text = Cookie["text2"] ;
}

Answer №1

MyDonation.Text = Request.Cookies["data"]["donate"];
 MyItem.Text = Request.Cookies["data"]["item"];
Here is a simple way to retrieve information from cookies.

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

Is it possible to utilize an API response within a conditional statement in NextJS?

I am working on a change password feature that interacts with an API for verification. If the current password entered is incorrect, I want to display an error message. If you have any suggestions on how to proceed or if there are any flaws in my approach ...

Textarea focus() function not functioning as expected in Chrome Extension with dynamically added text

Although I have come across many similar questions, it appears that I am still missing a key piece of information. My issue revolves around appending an HTML div tag upon clicking a button. Within this appended div tag lies a textarea tag that should auto ...

What could be the reason for receiving an array of promises instead of data while fetching information from the blockchain using useEffect?

I've encountered an issue while working with React and fetching data from the blockchain using useEffect. The problem arises when I map the data and store it in the lendingData array - upon logging, it appears as though I'm getting an array of pr ...

Error encountered on Next.js boilerplate development server

As I embark on my journey to learn next.js, I decided to install create-next-app and attempted to start a development server without making any changes to the boilerplate code provided. However, I encountered the following error: ./styles/globals.css Globa ...

An effective approach to positioning HTML elements at specific X and Y coordinates

I have an innovative project idea! The concept is to enable users to create points by clicking on the display. They can then connect these points by clicking again. However, I am facing a challenge when it comes to creating HTML elements at the exact loc ...

Using AngularJS to fetch images from RSS feed description

I'm currently learning AngularJS by creating a simple RSS feed. I have successfully made a JSON request and fetched all the data including title, link, description, and images from the RSS feed I parsed. The code snippet for extracting images looks li ...

Resolving .Net Assembly Binding Issues When Public Key Tokens Differ

Can an assembly binding redirect be performed between different versions of a referenced assembly when the older version has a null public key token and the newer version has one set? For instance, I have two assemblies... System.Web.Mvc, Version=1.0.0.0 ...

Can `void *` be considered a variable type that is constantly changing?

Whenever I think about void *, it strikes me as the dynamic typing equivalent in C & C++, often used lightheartedly. I attempted to search for a definition of "Dynamic Type" on Wikipedia or in a dictionary, but couldn't find any results. Is this ...

Integrating Endless Scrolling feature into current website

We are currently working on incorporating infinite scroll functionality into our existing website. Currently, we have an image that says 'click for more' which triggers an ajax call to the method GetArticlesFromNextSection(true). This method retu ...

Is it possible to search for a value within an array of objects in MongoDB, where the value may be found in any object within that array?

Here is the schema: {"_id":"_vz1jtdsip", "participants":{ "blue":["finettix"] "red":["EQm"] }, "win":"red"," __v":0} I have multiple documents l ...

What is the best way to consistently position a particular row at the bottom of the table in AG-grid?

I have successfully implemented a table using AG-grid. Here is the code snippet: .HTML <ag-grid-angular #agGrid style="width: 100%; height: 100%; font-size: 12px;" class="ag-theme-alpine" [rowData]=&quo ...

"Exploring the Power of Asp.net Identity and Dependency Injection

Am I the only one who finds using an IoC container with the latest Identity membership system for .Net to be a bit overwhelming? I have been attempting to navigate through the example project provided here that utilizes Unity: https://github.com/trailmax/ ...

What is the method for establishing an interval, removing it, and then reinstating the interval with the identical ID?

I'm wanting something along these lines: Inter = setInterval(Function, 1000); clearInerval(Inter); Inter = setInterval(Function, 1000); I've tried something similar without success. It's hard to explain all the details in a tidy way. Can a ...

I'm unsure why process.env.BACKEND_URL displays as undefined in the console, but appears correctly in a button within my Next.js application

I've encountered a challenge with environment variables while working on a Next.js project. In my Home component, I'm attempting to print the value of process.env.BACKEND_URL to the console and display it within a button. 'use client' i ...

What is the best way to organize arrays that are pointed to by an array of pointers

Is there a more effective way to sort arrays pointed by an array of pointers with the getSort function? void getSort(int** p2a, int arrSizes[]) //p2a is an array of pointers to different arrays An attempt was made using bubble sort: if (i < 5) { ...

Controlling setInterval internally in JavaScript: A guide

While developing my application, I have implemented the following code snippet: setInterval(function() { // some code // goes here }, 60000); The goal is to run certain code on a 1-minute interval, but sometimes it may take 2-3 minutes to complete. ...

How can we export data to excel using react-export-excel while ensuring certain columns are hidden?

Greetings! I believe the title gives you a clear idea of my dilemma. When exporting data, there are no errors - my goal is to hide the Excel column when the checkbox is unchecked or false, and display it when the checkbox is checked or true during export. ...

Creating a communal queue for a multi-process program in C/C++

Can anyone provide a solid example of a C/C++ multi-process shared queue (FIFO)? I am specifically excluding thread-based implementations, although suggestions for multi-threaded approaches are welcome. I need an implementation that can seamlessly integra ...

Failed commitments in JavaScript without a catch block (unhandled rejection)

When working on my project in VueJs JavaScript, I want to be able to see console messages if any of my Promises are not fulfilled and do not have a catch block. I attempted using the following code: Promise.reject("error!"); window.addEventListener(&apos ...

Tips for displaying an array in a tabular layout using angularjs

API calls are my jam, and I'm trying to display the JSON results in a nice tabular format using angularjs. To achieve this, I've set up a function (myfunc) with a hardcoded array called train. Now all that's left is to print this array in a ...