Wednesday, January 4, 2012

Clear/Remove QueryString value in asp.net

In general query string not clear using following
Request.QueryString.Remove("id");
Request.QueryString.Clear();
you get error like Collection readolny

but we can solve this following code

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("id");

No comments:

Post a Comment