AspnetO

We code, that works!

  • Home
  • Asp.net
  • MVC
  • Interview Questions
You are here: Home / Asp.net / Pass Multiple Parameters in Asp.net QueryString Example

Pass Multiple Parameters in Asp.net QueryString Example

By: Mayank Modi | Falls In: Asp.net, C#, Interview Questions, VB | Last Updated: Jun 01, 2020

In in this tutorial, I’ll explain as to how you can pass multiple parameters in asp.net querystring url and get parameter values on page load event of another page in asp.net using c# as well as vb.net. I would also demonstrate an example code and step by step guide.

Just for refreshing, you can also check out my previous tutorials, in which I had explained how to pass & (ampersand) as a querystring parameter value, how to get querystring paramters value using jquery, and exporting gridview data to word excel text and pdf.  I have also posted tutorials on GridView, Asp.net.

 

The QueryString collection is used to retrieve the variable values in the HTTP query string. The HTTP query string is specified by the values following the question mark (?).

Simple Asp.net QueryString URL Example With Single Parameter

protected void btnSubmit_Click(object sender, EventArgs e)
{
Response.Redirect(“Page2.aspx?id=” + txtId.Text);
}

As you can see from the above query string example (just after “?”), we are passing the parameters in key:value pair, meaning that id is a key variable and txtId.Text is a value of that key.

Note: To pass more than one parameter within the query string url, we need to use & (ampersand) to separate the parameters. Check below for the complete example.

For this tutorial, I created two pages, Page1.aspx is used to redirect the user to another page with a query string and another page is Page2.aspx to get the parsed query string data and display on a webpage.

Pass Multiple Parameters in Asp.net QueryString – [Page1.aspx]

Add the following code to your Page1.aspx Page as follows:

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head id=”Head1″ runat=”server”>
<title>Set QueryString Data From Code-behind</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<h4>Page1.aspx: Enter Employee Details</h4>
<table>
<tr>
<td>Employee Id:</td>
<td><asp:TextBox ID=”txtId” runat=”server” /></td>
</tr>
<tr>
<td>Employee Name:</td>
<td><asp:TextBox ID=”txtName” runat=”server” /></td>
</tr>
<tr>
<td>Designation:</td>
<td><asp:TextBox ID=”txtDesig” runat=”server” /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<asp:Button ID=”btnSubmit” runat=”server” Text=”Submit” OnClick=”btnSubmit_Click” />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

As you can see from the above code, I used OnClick event from where we will redirect users to another page with query string. Now add the following code snippet to your code-behind file of Page1.aspx as below.

Pass Multiple Parameters in Asp.net QueryString – [C#/Vb.net]

If you are using C# as code-behind, use the following code:

protected void btnSubmit_Click(object sender, EventArgs e)
{
Response.Redirect(“Page2.aspx?id=” + txtId.Text + “&name=” + txtName.Text
+ “&desig=” + txtDesig.Text);
}

If you are using Vb.net as code-behind, then use the following code:

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
Response.Redirect(“Page2.aspx?id=” & txtId.Text & “&name=” & txtName.Text
& “&desig=” & txtDesig.Text)
End Sub

To get the query string values to another page, we need to use the following code to the page that we mentioned in query string url. I used Page2.aspx as example.

Get QueryString URL Parameter Values To Another Page – [Page2.aspx]

Add the following code to your Page2.aspx Page as follows:

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head id=”Head1″ runat=”server”>
<title>Get QueryString Data From Another Page in Asp.net</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<h4>Page2.aspx: Get Employee Details From Previous Page QueryString</h4>
<b>Employee Id:</b>
<asp:Label ID=”lblId” runat=”server” />
<br />
<b>Employee Name:</b>
<asp:Label ID=”lblName” runat=”server” />
<br />
<b>Designation:</b>
<asp:Label ID=”lblDesig” runat=”server” />
</div>
</form>
</body>
</html>

Add the following code snippet to your code-behind file of Page2.aspx as below.

Get QueryString URL Parameter Values To Another Page – [C#/Vb.net]

If you are using C# as code-behind, use the following code:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblId.Text = Request.QueryString[“id”];
lblName.Text = Request.QueryString[“name”];
lblDesig.Text = Request.QueryString[“desig”];
}
}

If you are using Vb.net as code-behind, use the following code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
lblId.Text = Request.QueryString(“id”)
lblName.Text = Request.QueryString(“name”)
lblDesig.Text = Request.QueryString(“desig”)
End If
End Sub

How to pass &(ampersand) within QueryString URL?

You can learn more about passing & (ampersand) within querystring parameter value here.

How to Get QueryString Parameter Value using JavaScript/jQuery?

You can learn more about how to get querystring parameter value from client-side using jquery here.

Example Result

When you click on the submit button, you will be redirected to Page2.aspx with the following query string:

http://localhost:4426/Page2.aspx?id=EMP0001&name=Mack%20John&desig=Managing%20Director

And here is the result generated from the above example:

Asp.net QueryString URL Example to Pass Multiple Parameters using C# Vb.net

Download Example

Icon

Asp.net QueryString URL Example to Pass Multiple Parameters

1 file(s) 30.64 KB
Download This Example

Git Repo

git clone https://github.com/immayankmodi/query-string-multi-parameters-asp-net-c-vb.git

Signup Today And Get Latest Tutorials For Free!

Subscribe to us and get free latest tutorials notifications whenever we publish a new contents.

<

About Mayank Modi

Mayank is a web developer and designer who specializes in back-end as well as front-end development. He's a Founder & Chief Editor of AspnetO. If you'd like to connect with him, follow him on Twitter as @immayankmodi.

Comments

  1. Lana Pieczynski says

    Oct 30, 2019 at 6:25 AM

    This was exactly the solution I was looking for! Thank you so much. I have spent the better part of 2 days trying to get my gridviews to handle filtering criteria correctly – and I just felt like I was going backwards. This solution worked perfectly! 🙂 I really appreciate it!

    Reply

Leave a Reply Cancel reply

Search Your Topic



Social Connections

  • 1,438 Fans
  • 3,087 Followers
  • 50 Followers
  • 1,559 Subscribers

Get Latest Tutorials For Free



Top Posts

  • Pass Multiple Parameters in Asp.net QueryString Example
  • CSS3 Transition: fadeIn and fadeOut like Effects to Hide Show Elements
  • Show Confirm Message Box from Code-behind in Asp.net
  • Call JavaScript Function from Code-behind in Asp.net C# Vb
  • Send HTML Webpage Content as Email Body in Asp.net C# Vb.net

Contribute to AspnetO

If you want to contribute your unique blog articles or tutorials (Free / Paid) to AspnetO in any languages, you're most welcome. Just send me your previous articles, and topics on which you are interested to post an tutorial. Contact us at email listed in contact us page. Selected candidates will be contacted.

Search by Tags

Ado.net Ajax appSettings Asp.net C# CheckBox CheckBoxList ConnectionStrings Control CSS CSS3 Difference Download DropDownList Export Facebook fadeIn fadeOut fadeTo fadeToggle File File Extension FileUpload Function GridView IIS Interview Questions JavaScript jQuery MVC OOP RadioButtonList RDP Repeater Send Mail Solutions Split SQL Stored Procedure TextBox Upload Validation VB Web.config Web Hosting

The Man Behind AspnetO

Mayank Modi

Hi there,

Myself Mayank Modi, a Full Stack Developer (.NET Stack) and a blogger from Surat, India.

I'm welcoming you to my blog - AspnetO, a programmers community blog where we code, that works!

I started AspnetO as a hobby and now we're growing day by day. We're now having 5000+ programmers that get benefits and learn new things about website design and development under our community blog.

Here at AspnetO, I write about Beginners to Advance level of tutorials on programming languages like Asp.net using C# and Vb.net, MVC, SQL Server, JavaScript, jQuery etc. In sort, all about .NET Framework and website development stuff and sometimes sharing tips and tricks that can help you to grow up your programming skills.

You can get more details about me and my blog at About us page.

Subscribe To Newsletter

Enter your email address to subscribe to this blog and receive notifications of new posts right to your inbox

Join 1000+ other subscribers

<

Recent Posts

  • Main Difference between SessionState and ViewState in Asp.net
  • How to Get appSettings Value from Web.config File?
  • How to Get ConnectionString from Web.config in Asp.net?
  • Difference between appSettings and connectionStrings in Web.config
  • Get Folder Files List and Export to CSV in .NET
  • Get Files List From Directory Recursively in C# Vb.net
  • Get Hash Value From Current Page URL In jQuery
  • Handle Multiple Submit Buttons in Single MVC Form

Copyright © 2014 - 2021 · All Rights Reserved.

About | Copyrights | Privacy | Terms | Contact | Advertise | Sitemap
Previous Pass DataTable in Stored Procedure Parameter in .Net
Next Asp.net Passing &(ampersand) in QueryString Parameter Value