---
title: "Query String in ASP.Net"  
description: "When working with websites, you often need to pass values from one page to another like data from html page to aspx web forms in context of Asp.Net"  
author: "Sumit Kesarwani"  
published: 2013-05-14  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/1296/query-string-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 4 minutes  

---

# Query String in ASP.Net

When working with websites, you often need to pass values from one page to another like data from html page to aspx [web forms](https://www.mindstick.com/interview/33689/is-mvc-replacing-asp-dot-net-web-forms) in [context of Asp.Net](https://www.mindstick.com/forum/158603/explain-the-concept-of-middleware-in-the-context-of-asp-dot-net-core)\

For example in first page you collect information about your client, first name and

last name and use this information in your [second page](https://www.mindstick.com/forum/23130/windows-phone-8-1-universal-app-terminates-on-navigating-back-from-second-page).

For passing [variables](https://www.mindstick.com/articles/715/php-variables) content between pages ASP.NET gives us several choices. One choice is using [QueryString](https://www.mindstick.com/interview/123/what-is-querystring-benefits-and-limitations-of-using-querystring) property of Request Object. When surfing [internet](https://yourviews.mindstick.com/view/81617/now-it-is-time-to-say-goodbye-to-internet-explorer) you should have seen weird internet address such as one below.

http://www.localhost.com/Webform2.aspx?[Firstname](https://www.mindstick.com/interview/33973/how-to-split-the-full-name-into-firstname-and-lastname-in-sql-server)=Sumit&LastName=Kesarwani

This html addresses use QueryString property to pass values between pages. In this

address you send 3 information.

Webform2.aspx this is the page your browser will go.

Firstname=Sumit you send a Firstname variable which is set to Sumit

LastName=Kesarwani you send a Lastname variable which is set to Kesarwani

As you have guessed ? starts your QueryString, and & is used between variables.

##### Example

##### Step 1:-

Design the form as shown below:

![Query String in ASP.Net](https://www.mindstick.com/mindstickarticle/94ab3042-7ef4-4891-81c4-c10247bd2ea3/images/9d92ea87-9aea-4527-b660-ab3f5403523d.png)

```
 
    <div>        <table>            <tr>                <td>                    Firstname                </td>                <td>                    <asp:TextBox ID="txtFirstname" runat="server"></asp:TextBox>                </td>            </tr>            <tr>                <td>                    Lastname                </td>                <td>                    <asp:TextBox ID="txtLastname" runat="server"></asp:TextBox>                </td>            </tr>            <tr>                <td>                </td>                <td>                    <asp:Button ID="btnSend" runat="server" Text="Send Values"                        onclick="btnSend_Click" />                </td>            </tr>        </table>
    </div> 
```

##### Step 2:-

Write the following code in webform1.aspx.cs

```
using System; 
namespace QueryStringWebApplication{    public partial class WebForm1 : System.Web.UI.Page    {
        protectedvoid Page_Load(objectsender, EventArgse)        {
        }
        protectedvoid btnSend_Click(objectsender, EventArgse)        {
            Response.Redirect("WebForm2.aspx?Firstname="+ txtFirstname.Text+"&Lastname="+txtLastname.Text);
        }    }
}
```

Step 3:-

Add another form webform2.aspx

```
    <div>        Firstname : <asp:LabelID="lblFirstname" runat="server"></asp:Label>
        <br/>
        Lastname : <asp:LabelID="lblLastname" runat="server"></asp:Label>
    </div> 
```

##### Step 4:-

Write the following code in webfrom2.aspx.cs file

```
using System; namespace QueryStringWebApplication{
    public partial class WebForm2 : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgse)        {            if (!IsPostBack)            {
                lblFirstname.Text=Request.QueryString["Firstname"];                lblLastname.Text=Request.QueryString["Lastname"];
            }
        }
    }
}
```

Step 5:-

Run the application

![Query String in ASP.Net](https://www.mindstick.com/mindstickarticle/94ab3042-7ef4-4891-81c4-c10247bd2ea3/images/131f8d28-dcb7-4808-afd1-2e103c0ffa72.png)

After filling the values click on the send values button

![Query String in ASP.Net](https://www.mindstick.com/mindstickarticle/94ab3042-7ef4-4891-81c4-c10247bd2ea3/images/d177c71d-89c1-4487-8d14-093dcee89533.png)

It will redirect to you on webform2.aspx page and show the message like this.

![Query String in ASP.Net](https://www.mindstick.com/mindstickarticle/94ab3042-7ef4-4891-81c4-c10247bd2ea3/images/665a6236-b8da-4007-ad5a-f80f519f8068.png)

And also you can see that the values passed are on the URL.

---

Original Source: https://www.mindstick.com/articles/1296/query-string-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
