Query Strings Explained in ASP.NET

Introduction

In this blog, I will explain Query Strings in ASP.NET websites. Query Strings are one of the client-side state management techniques. It is a very simple technique used to pass data from one web page to another. You can also send requests to the web server. These requests pass information from one page to another page and the Query String in ASP.Net accesses this information on the receiving page. It contains the HTTP request for a specific URL and is used to retrieve the variable values in the HTTP query string.
 
WebForm1.aspx.cs
  1. protected void BtnSubmit_Click(object sender, EventArgs e)  
  2.          {  
  3.            Response.Redirect("Webform2.aspx?UserName=" + TxtUserName.Text+"&&Password="+TxtPwd.Text);  
  4.          }  
WebForm2.aspx.cs
  1. protected void Page_Load(object sender, EventArgs e)  
  2.        {  
  3.            if(Request.QueryString["UserName"]!=null&& Request.QueryString["Password"] != null)  
  4.            {  
  5.                  lbltext.Text = "Welcome to " + Request.QueryString["UserName"].ToString()  +" "+ Request.QueryString["Password"].ToString();  
  6.            }  
  7.             
  8.        }  
Output
 
 
Advantages
  1. Query strings are easy to implement.
  2. Query strings contain the HTTP request for a specific URL.
  3. All browsers support query strings.
  4. They don’t require server resources.