Clear or Remove query string in ASP.Net

Removing (Deleting) Querystring in ASP.NET

Request.QueryString.Remove("editFlag")

If you do the above, you will get an error

collection is read-only.

So, we need to write the below code before deleting the query string.

Try this way

PropertyInfo isreadonly = 
  typeof(System.Collections.Specialized.NameValueCollection).GetProperty(
  "IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
// make collection editable
isreadonly.SetValue(this.Request.QueryString, false, null);
// remove
this.Request.QueryString.Remove("editFlag");

You can also try this way

    var nvc = HttpUtility.ParseQueryString(Request.Url.Query);
    nvc.Remove("editFlag");
    string url = Request.Url.AbsolutePath + "?" + nvc.ToString();
     Response.Redirect(url);

Hope this helps

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)