Removing Data From query string

Posted by Niranjan_13 under ASP.NET on 1/10/2013 | Points: 10 | Views : 1220 | Status : [Member] | Replies : 3
How we remove data from query string
i try with

Request.QueryString.Remove("");
Request.QueryString.clear("");

but it does'nt work
it give the error message it's read only property.

Niranjan Pandey


Responses

Posted by: muralikrishnasurap-12704 on: 1/10/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Niranjan_13 ,

we can't use clear(or) remove methods since the QueryString collection is readoonly ,if still you want to clear you can use fallowing code.

  PropertyInfo isreadonly = typeof(NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);

isreadonly.SetValue(Request.QueryString, false, null);
this.Request.QueryString.Clear();


Best Regards
Murali Krishna.S

Niranjan_13, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sourabh07 on: 1/18/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

I don't think you can clear query strings unless you redirect the page. Untill the page is relaoded, any query strings will stay as it is part of the url.

If displaying the query strings is an issue, then you should consider url rewriting.

Sourabh07

Niranjan_13, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Guna27 on: 1/18/2013 [Member] Starter | Points: 25

Up
0
Down
Yes we can't clear the query string value bcz it is read only. so we need to call Redirect to same page.

Guna..............

Niranjan_13, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response