querystring asp net code example

Example 1: querstring fromat asp.net c#

public partial class QueryStringValuesTransfer : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string id1 = Server.UrlDecode(Request.QueryString["id"]);
        string name1 = Server.UrlDecode(Request.QueryString["name"]);
        Response.Write(id1 + name1);

    }

Example 2: string.QueryString c#

// Adding a second parameter with the same name (round 2).
  StringValues twoValues = StringValues.Concat(queryString["param2"], "my other value");
  parsedQueryString["coronavirus"] = twoValues;

  // Getting a param value
  var param2Value = queryString["param2"];
  // --> StringValues!

  param2Value.ToString(); // Get the values concatenated together
  param2Value.ToArray(); // Gets an array of strings

  // Modifying a parameter
  queryString["param1"] = "another value";
  // NOTE, if there were two values,
  // this overwrites both and leaves a single value.

  // Url Encoding the whole thing
  QueryString.Create(parsedQueryString).ToString();
  // --> "?param1=another%20value¶m2=my%20value¶m2=my%20other%20value