---
title: "QueryString in ASP.Net"  
description: "We use QueryString property of Request Object for passing variables content between pages ASP.NET. QueryStrings are data that is appended to the end o"  
author: "Dev Vrat Sahu"  
published: 2012-08-28  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/984/querystring-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# QueryString in ASP.Net

We use [QueryString](https://www.mindstick.com/interview/123/what-is-querystring-benefits-and-limitations-of-using-querystring) [property](https://www.mindstick.com/articles/198559/an-ownership-of-property-in-hua-hin) of Request Object for passing [variables](https://www.mindstick.com/articles/715/php-variables) content between pages ASP.NET. QueryStrings are data that is appended to the end of a page URL. They are commonly used to hold data like page numbers or search terms or other data that isn't confidential.

##### Example

Here is the example which shows you to Pass the values in QueryString and further [retrieve](https://www.mindstick.com/forum/34400/how-to-retrieve-form-values-in-controller-action) it.

**1.** Create a page named Default.aspx and design the following UI.

\
![QueryString in ASP.Net](https://www.mindstick.com/mindstickarticle/dd291c5d-5f3c-4694-9596-336897d7967d/images/b0ab212e-2b5a-4311-acb2-c25a715a68d2.png)

On Next Button Click Event Handler write the following code

```
protected void btnNext_Click(object sender, EventArgs e)    {        // it will Pass the value and call the Result.aspx page        Response.Redirect("Result.aspx?Num1=" +txtNum1.Text + "&Num2=" +txtNum2.Text);    }
```

**2.** Now Create another page names Result.aspx and design the following UI.

![QueryString in ASP.Net](https://www.mindstick.com/mindstickarticle/dd291c5d-5f3c-4694-9596-336897d7967d/images/9be8c225-c3fb-4b7e-ade5-3526f9d60d7c.png)

**3.** Write the following code on Page_Load() of Result.aspx

```
string operation = "";    double number1,number2,result;    protected void Page_Load(object sender, EventArgs e)    {               if (Page.IsPostBack== false)        {            //Getting the value fromQueryString            txtNum1.Text= Request.QueryString["Num1"];            txtNum2.Text= Request.QueryString["Num2"];                   }           }
```

**4.** On Get Result Button Click [Event Handler](https://www.mindstick.com/forum/1371/c-sharp-dot-net-event-handler-delegate-question) write the following code

```
 protected void btnCalculate_Click(object sender, EventArgs e)    {        number1 = Convert.ToDouble(Request.QueryString["Num1"]);        number2 = Convert.ToDouble(Request.QueryString["Num2"]);        operation = cbOperation.SelectedValue.ToString();        switch (operation)        {            case "Add":                result = number1 + number2;                break;            case "Subtract":                result = number1 - number2;                break;            case "Multiply":                result = number1 * number2;                break;            case "Divide":                result = number1 / number2;                break;            default:                result = 0;                break;        }        lblResult.Text = result.ToString();    }
```

**5.** Now, focus to **Default.aspx** page and run the Website.

**6.** Give the [Required](https://yourviews.mindstick.com/view/81031/vigilence-required-during-corona-pandemic) value and then Click **Next** Button.

**7.** On Next Page, Value in the [textboxes](https://www.mindstick.com/forum/34206/how-to-add-5-dynamic-textboxes-in-wpf-and-how-to-write-binding-in-c-sharp) will be filled automatically with the help of value passed in QueryString from **Default.aspx** page.

**8.** Choose the desired [operation](https://yourviews.mindstick.com/view/83916/why-is-it-necessary-to-sterilize-operation-theater) and Click **Get Result** Button to Get the result of the calculation.

##### Output Window 1.0

![QueryString in ASP.Net](https://www.mindstick.com/mindstickarticle/dd291c5d-5f3c-4694-9596-336897d7967d/images/9c447965-d2f0-4089-a7f4-f3ccdda2ccc1.png)

##### Output Window 1.1

![QueryString in ASP.Net](https://www.mindstick.com/mindstickarticle/dd291c5d-5f3c-4694-9596-336897d7967d/images/73ffc93a-7f0c-4b3c-8cf8-28cfaddcfa5e.png)

\

---

Original Source: https://www.mindstick.com/articles/984/querystring-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
