views:

589

answers:

3

Assume I have the link http://www.somesite.com/file.aspx?a=1&b=2

And now I want to remove all the parameters, so it becomes:

http://www.somesite.com/file.aspx

Or I may want to remove only 1 of the parameters such as

http://www.somesite.com/file.aspx?b=2

Is there a way to do the above in C#? What is happening is that I am coming from another page with a parameter called edit in the url, but when the page does a post back, the edit parameter is still there, so it still thinks it is in edit mode. Example:

User A goes to page one.aspx and clicks on an edit link. They are taken to two.aspx?edit=true. During page load, it sees the the query string parameter edit is not null and it puts the contents in edit mode. Once the user is done editing, the page is refreshed, but the url is still two.aspx?edit=true and keeps the contents in edit mode, when in fact it should be two.aspx

+4  A: 

Request.Querystring is read-only collection - You cannot modify that.

If you need to remove or change the param in querystring only way out is to trigger a new GET request with updated querystring - This means you will have to do Response.Redirect with updated URL. This will cause you lose the viewstate of the current page.

this. __curious_geek
That's what I actually was doing, so I guess I am stuck with that. Thanks.
Xaisoft
+1  A: 

When you are done with the edit you are doing a post back so just define the action to post to two.aspx instead of just posting back to itself that way it will drop off the get parameters.

Jeff Beck
A: 

How about checking Page.IsPostBack to see if the current request is a postback or not?

RickNZ