---
title: "Transferring Data between ASP.NET Web Pages"  
description: "In most of the Web Application, so many times it is required to pass/transfer data between pages or one page to another. Requirements like maintaining"  
author: "Anonymous User"  
published: 2012-09-11  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/367/transferring-data-between-asp-dot-net-web-pages  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 3 minutes  

---

# Transferring Data between ASP.NET Web Pages

In most of the [Web Application](https://www.mindstick.com/articles/13069/progressive-web-application-pwas-all-you-need-to-know-about), so many times it is required to pass/[transfer data](https://www.mindstick.com/forum/34257/how-can-transfer-data-from-one-activity-to-another-activity-in-android) between pages or one page to another. Requirements like maintaining [user preferences](https://www.mindstick.com/forum/159311/implement-a-react-component-that-sorts-and-filters-data-based-on-user-preferences) across the application, identifying user between transactions, correlating data based on previous page options etc, always leads programmers to write code to pass/transfer data from page to page.\

There are several ways to accomplish the task to transfer data between pages. It can be a advantage to programmer to use these techniques according to their requirements other –wise selecting a inappropriate techniques in a situation may leads to wastage of time.

· [Data Transfer](https://answers.mindstick.com/qa/102452/how-do-external-ssds-contribute-to-faster-data-transfer) Techniques are:

· QueryString

· Cookies

· Hidden Fields

· View State

· [Session Variable](https://www.mindstick.com/forum/12804/how-to-set-a-asp-dropdownlist-selectedvalue-to-a-session-variable)

· Application Variables

1. [Query String](https://www.mindstick.com/articles/512/query-string-in-asp-dot-net):

A query string is information that is appended to the end of a page URL. A query string is a collection of name/value pairs which are appended to a URL. They are separated from the location of the resource by a **[question mark](https://answers.mindstick.com/qa/49900/how-to-fix-a-mac-with-a-flashing-question-mark)** ‘?’. QueryString method has the advantage of using simple, do not use server resources; drawback is that the value passed will be displayed in the browser’s [address bar](https://www.mindstick.com/forum/70/how-can-we-remove-address-bar-of-browser), the risk of being tampered with.

##### Syntax:

Passing the Value from Page A.aspx

```
Response.Redirect("B.aspx?varA="+TextBox1.Text);
```

[Getting the value](https://www.mindstick.com/forum/182/problem-in-getting-the-value-from-array-by-using-foreach-loop) from Page B.aspx

string varB = Request.QueryString["varA"].ToString();

2. Cookies:

Cookie is a small text file sent by web server and saved by [web browser](https://www.mindstick.com/blog/301688/best-web-browsers-for-2023) on client machine. Cookies are created when a user's browser loads a particular website. The website sends information to the browser which then creates a text file. Every time the user goes back to the same website, the browser retrieves and sends this file to the website's server.

##### There are two types of cookies available in .Net

· Non Persistent / Session Cookies

· Persistent Cookies

##### Non Persistent / Session Cookies

Non Persistent cookies are stored in memory of the client browser session, when browsed is closed the non persistent cookies are lost.

##### Persistent Cookies

Persistent Cookies have an expiration date and theses cookies are stored in Client hard drive.

Syntax:Creating Cookies and Storing Value in it.

```
//Creating Object for HttpCookie Class and Named it "UserInfo"   HttpCookie objCookie = new HttpCookie("UserInfo");   objCookie["UserName"] = TextBox1.Text.ToString();   objCookie["Password"] = TextBox2.Text.ToString();   //Specified time limit for cookie to accessed   objCookie.Expires = DateTime.Now.AddMinutes(30);   Response.Cookies.Add(objCookie);
```

##### Getting Value from Cookie

HttpCookie objRequestRead = Request.Cookies["UserInfo"];

Response.Write(objRequestRead["UserName"] + " " + objRequestRead["password"]);

Cookies are stored for 24 hrs, if you have not specified any time limit for Cookies Expiration.

##### 3. Hidden Fields

ASP.NET allows you to store information in a HiddenField control. A hidden field does not render visibly in the browser, but you can set its properties just as you can with a standard control. When a page is submitted to the server, the content of a hidden field is sent in the HTTP form collection along with the values of other controls. A hidden field acts as a repository for any page-specific information that you want to store directly in the page. Hidden fields' data is submitted to the server only in HTTP post operation. The value is saved as a string and therefore in order to use it for other types you need to perform casting.

##### Syntax:

##### //Creating and Assigning value to Hidden Filed

```
<asp:HiddenField ID="HiddenField1" runat="server" Value="0"/>        <br /><asp:Button ID="Button1" runat="server" Text="Click" />        <br /><asp:Label ID="Label1" runat="server" Text="Counter :"></asp:Label>
```

---

Original Source: https://www.mindstick.com/blog/367/transferring-data-between-asp-dot-net-web-pages

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
