Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
3.25/5 (4 votes)
See more:
Hi,

How to Clear the Query String value.

Example:
response.write("sample.aspx?id=3")


iam getting this value another page like

int id=request.querystring["id"];


I want to clear this value in update method.

iam using followings

Response.ClearContent();
Request.QueryString.Remove("id");  

but it is not clears

Thanks®ards
venkat
Posted
Updated 10-Oct-18 3:32am
v3

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



Hi solved this using the above code
 
Share this answer
 
v2
Comments
Rajesh Anuhya 5-Jan-12 8:21am    
You are not supposed to post here
murali21oct 17-Jul-13 10:03am    
Worked for me. Thanks!
[no name] 3-Feb-14 6:33am    
PropertyInfo doesnot contain method SetVAlues
you can use

Request.QueryString.Clear();

for clear all the query string
 
Share this answer
 
To clear all querystrings, you can invoke the Request.QueryString.Clear();
which will remove all the querystrings at the url
To remove a specific querystring invoke Request.QueryString.Remove("name of the querystring"),

example:

http://www.mypage.aspx?id=123


Request.QueryString.Remove("id");

or you can use

Request.QueryString.Clear();

which will remove or the querystrings

example

http://www.mypage.aspx?id=123&date=29/8/2008


Request.QueryString.Clear();

result
Url without the two querystrings (id,date);
 
Share this answer
 
v2
Comments
Emad Al Hawary 4-Jan-12 23:48pm    
ALSO TRY TO POST IF YOU WANT TO HIDE
zadeabhi 26-Feb-13 2:29am    
Request.QueryString.Clear();
won't work as "QueryString" collection is read only, you can't use that directly it will throw exception as "Collection is read-only".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900